From 39192ff42d436c95dc6143f0373cf21ab7cebed7 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 21 Dec 2023 14:48:25 +0300 Subject: [PATCH] added Recipe comment --- database/factories/RecipeCommentFactory.php | 26 +++++++++++++++ database/seeders/RecipeCommentSeeder.php | 37 +++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 database/factories/RecipeCommentFactory.php create mode 100644 database/seeders/RecipeCommentSeeder.php diff --git a/database/factories/RecipeCommentFactory.php b/database/factories/RecipeCommentFactory.php new file mode 100644 index 0000000..678f38a --- /dev/null +++ b/database/factories/RecipeCommentFactory.php @@ -0,0 +1,26 @@ + + */ +class RecipeCommentFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + + return [ + 'grade' => $this->faker->randomDigit(), + 'body' => $this->faker->text(), + ]; + + } +} diff --git a/database/seeders/RecipeCommentSeeder.php b/database/seeders/RecipeCommentSeeder.php new file mode 100644 index 0000000..3b24f5c --- /dev/null +++ b/database/seeders/RecipeCommentSeeder.php @@ -0,0 +1,37 @@ + 0 && Recipe::count() > 0) { + $comments = RecipeComment::factory()->count(5)->make(); + + $comments->each(function ($comment) { + $comment->author()->associate( + User::inRandomOrder() + ->first() + ->id + ); + + $comment->recipe()->associate( + Recipe::inRandomOrder() + ->first() + ->id + ); + + $comment->saveOrFail(); + }); + } + } +}