forked from eatvio/eatvio-infra
added recipe author seeder
This commit is contained in:
25
database/seeders/RecipeAuthor.php
Normal file
25
database/seeders/RecipeAuthor.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
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(function ($recipe) {
|
||||
User::inRandomOrder()
|
||||
->first()
|
||||
->author_of_recipe()
|
||||
->attach($recipe->id);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user