Added comments to RecipeSeeder

This commit is contained in:
2023-12-15 14:04:01 +03:00
parent 14e0f36e76
commit e887e5eae1

View File

@@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Storage;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Recipe;
use App\Models\RecipeComment;
use App\Models\RecipeAuthor;
use App\Models\User;
use Faker\Factory as FakerFactory;
@@ -41,6 +42,14 @@ class RecipeSeeder extends Seeder
['name' => $faker->word, 'portion' => $faker->numberBetween(1, 20), 'unit' => $faker->randomElement(['teespoon', 'tablespoon', 'ml', 'pcs', 'clove', 'to_taste'])],
];
$recipe->save();
for ($j = 0; $j < 10; $j++) {
$comment = new RecipeComment();
$comment->user_id = User::inRandomOrder()->first()->id;
$comment->recipe_id = $recipe->id;
$comment->grade = $faker->randomElement([1,2,3,4,5]);
$comment->body = $faker->text(100);
$comment->save();
}
User::inRandomOrder()->first()->author_of_recipe()->attach($recipe->id);
}