forked from eatvio/eatvio-infra
28 lines
561 B
PHP
28 lines
561 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Recipe;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class RecipeAuthor extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
if (User::count() > 0 && Recipe::count() > 0) {
|
|
Recipe::each(static function ($recipe): void {
|
|
User::inRandomOrder()
|
|
->first()
|
|
->author_of_recipe()
|
|
->attach($recipe->id);
|
|
});
|
|
}
|
|
}
|
|
}
|