make()->each(function (Recipe $recipe) use (&$jj) { $recipe->picture = FileStorageHelper::storeFile($recipe, new \SplFileInfo(\resource_path( '../database/factories/assets/recipes/default-picture-1600x900.png' ))); $recipe->picture_thumbnail = FileStorageHelper::storeFile($recipe, new \SplFileInfo(\resource_path( '../database/factories/assets/recipes/default-picture-430x242.png' ))); $recipe->order = $jj; $recipe->saveOrFail(); $jj = $jj + 1; }); // Seeder for recipes_products table. $products = Product::query()->get(); Recipe::each(function (Recipe $model) use ($products) { $offset = rand(0, 50); $length = rand(0, 3); $model->products()->saveMany($products->slice($offset, $length)); }); } }