/** * Run the database seeds. * * @return void */ public function run() { factory(Category::class, random_int(1, 5))->create(); factory(Category::class, random_int(1, 10))->make()->each(function (Category $category) { $category->parent_id = Category::inRandomOrder()->first()->id; $category->save(); }); }
$file_name = 'currency-iso.xml'; $storage = Storage::disk('local'); if (!$storage->exists($file_name)) { $storage->put($file_name, file_get_contents($url)); } $xml = simplexml_load_string($storage->get($file_name)); $json = json_encode($xml); $array = json_decode($json, true); $currencies = $array['CcyTbl']['CcyNtry']; } $index = array_rand($currencies, 1); return ['name' => $currencies[$index]['CcyNm'], 'code' => $currencies[$index]['Ccy'], 'number' => $currencies[$index]['CcyNbr'], 'unit' => $currencies[$index]['CcyMnrUnts'] === 'N.A.' ? 0 : $currencies[$index]['CcyMnrUnts']]; }); $factory->define(Product::class, function (Faker\Generator $faker) { $content = $faker->paragraphs(random_int(1, 16), true); $description = str_limit(trim(strip_tags(nl2br($content))), 156); $name = $faker->name; return ['name' => $name, 'description' => $description, 'content' => $content, 'slug' => str_slug($name), 'price' => random_int(1, 10000000), 'published_at' => Carbon::now(), 'category_id' => Category::inRandomOrder()->first()->id, 'currency_id' => Currency::inRandomOrder()->first()->id]; }); $factory->define(Category::class, function (Faker\Generator $faker) { $content = $faker->paragraphs(random_int(1, 16), true); $description = str_limit(trim(strip_tags(nl2br($content))), 156); $name = $faker->word; return ['name' => $name, 'description' => $description, 'content' => $content, 'slug' => str_slug($name), 'published_at' => Carbon::now()]; }); $factory->define(Attachment::class, function (Faker\Generator $faker) { $url = 'https://source.unsplash.com/random'; $name = str_random(16) . '.jpg'; $property = app(\App\Services\ImageService::class)->make($url, $name); return ['file' => $name, 'dick' => 'local', 'property' => $property]; });