make()->each(function (Advice $advice) { $advice->picture = FileStorageHelper::storeFile( $advice, new \SplFileInfo(\resource_path( '../database/factories/assets/products/product_fake_650_690.jpg' )) ); $advice->sticker = FileStorageHelper::storeFile( $advice, new \SplFileInfo(\resource_path( '../database/factories/assets/products/product_fake_370_300.jpg' )) ); $advice->sticker_sm = FileStorageHelper::storeFile( $advice, new \SplFileInfo(\resource_path( '../database/factories/assets/products/product_fake_270_145.jpg' )) ); $advice->saveOrFail(); }); $this->call([ TagSeeder::class ]); // Seeder for taggable table. $tags = Tag::query()->get(); Advice::each(function (Advice $model) use ($tags) { $offset = rand(0, 9); $length = rand(1, 2); $model->tags()->saveMany($tags->slice($offset, $length)); }); // Seeder for advice_advice table. $advice = Advice::query()->get(); Advice::each(function (Advice $model) use ($advice) { $offset = rand(0, 9); $length = rand(0, 3); $model->advices()->saveMany($advice->slice($offset, $length)); }); // Seeder for advice_products table. $products = Product::query()->get(); Advice::each(function (Advice $model) use ($products) { $offset = rand(0, 24); $length = rand(1, 3); $model->products()->saveMany($products->slice($offset, $length)); }); } }