33 lines
948 B
PHP
33 lines
948 B
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Dish;
|
|
use App\Models\Planner;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class DishesSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$users = User::all();
|
|
$userOptions = collect([
|
|
[$users->first()],
|
|
[$users->last()],
|
|
[$users->first(), $users->last()],
|
|
]);
|
|
|
|
$planner = Planner::all()->first() ?? Planner::factory()->create();
|
|
|
|
collect([
|
|
'lasagne', 'pizza', 'burger', 'fries', 'salad', 'sushi', 'pancakes', 'ice cream', 'spaghetti', 'mac and cheese',
|
|
'steak', 'chicken', 'beef', 'pork', 'fish', 'chips', 'cake',
|
|
])->map(fn (string $name) => Dish::factory()
|
|
->create([
|
|
'planner_id' => $planner->id,
|
|
'name' => $name,
|
|
])
|
|
)->each(fn (Dish $dish) => $dish->users()->attach($userOptions->random()));
|
|
}
|
|
}
|