46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders\Development;
|
|
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
use App\Models\Product;
|
|
use App\Models\Recipe;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class RecipeSeeder extends Seeder
|
|
{
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = Recipe::class;
|
|
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run(): void
|
|
{
|
|
Recipe::factory(20)->make()->each(function (Recipe $recipe, int $index) {
|
|
$recipe->picture = FileStorageHelper::storeFile(
|
|
$recipe,
|
|
new \SplFileInfo(\resource_path(
|
|
'../database/factories/assets/recipes/default-picture-720x405.png'
|
|
))
|
|
);
|
|
$recipe->highlight = ($index === 0) ? true : false;
|
|
$recipe->saveQuietly();
|
|
|
|
DB::table('productables')->insert(
|
|
[
|
|
'product_id' => Product::inRandomOrder()->first()->getKey(),
|
|
'productable_id' => $recipe->getKey(),
|
|
'productable_type' => 'App\Models\Recipe'
|
|
]
|
|
);
|
|
});
|
|
}
|
|
}
|