From ad2a02797470fcf27335c44885e212f8ffab0bda Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 21 Dec 2023 14:34:42 +0300 Subject: [PATCH 1/7] added recipe factories --- database/factories/RecipeFactory.php | 85 ++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 database/factories/RecipeFactory.php diff --git a/database/factories/RecipeFactory.php b/database/factories/RecipeFactory.php new file mode 100644 index 0000000..bc17a8f --- /dev/null +++ b/database/factories/RecipeFactory.php @@ -0,0 +1,85 @@ + + */ +class RecipeFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + $faker = \Faker\Factory::create(); + $this->faker->addProvider(new Restaurant($faker)); + $this->faker->addProvider(new Youtube($faker)); + + return [ + 'title' => $this->faker->foodName(), + 'image' => $this->generateImageFile('recipes'), + 'state' => $this->faker->randomElement(['active', 'archived']), + 'cooking_time' => $this->faker->numberBetween(0, 59), + 'ingredients' => $this->createQuentityIngredients($this->faker->randomDigitNotNull()), // quentity - от 1 до 10 randomDigitNotNull + 'type' => $this->faker->randomElement(['first_meals', 'second_meals', 'salads', 'snacks', 'drinks', 'other']), + 'description' => $this->faker->text(), + 'steps' => $this->createQuentitySteps($this->faker->randomDigitNotNull()), + 'video_url' => $this->faker->youtubeRandomUri(), + ]; + } + + private function generateImageFile(string $name) + { + Storage::fake($name); + $file = UploadedFile::fake()->image($name . '.png'); + return $file->store($name, 'public'); + } + + private function generateIngredients(): array + { + return [ + 'name' => $this->faker->foodName(), + 'unit' => $this->faker->randomElement(['гр', 'ч. ложек', 'cт. ложек', 'мл', 'шт', 'зубчик', 'по вкусу']), + 'portion' => $this->faker->randomNumber(3, true), + ]; + } + + private function generateSteps(): array + { + return [ + 'image' => $this->generateImageFile('steps'), + 'description' => $this->faker->text(), + ]; + } + + private function createQuentitySteps($count) + { + $result = []; + + for ($i = 0; $i < $count; $i++) { + $result[] = $this->generateSteps(); + } + + return $result; + } + + private function createQuentityIngredients($count) + { + $result = []; + + for ($i = 0; $i < $count; $i++) { + $result[] = $this->generateIngredients(); + } + + return $result; + } +} From fba048f063461398a3c39b2607b9336081b8e468 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 21 Dec 2023 14:35:16 +0300 Subject: [PATCH 2/7] added recipe seeder --- database/seeders/RecipeSeeder.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 database/seeders/RecipeSeeder.php diff --git a/database/seeders/RecipeSeeder.php b/database/seeders/RecipeSeeder.php new file mode 100644 index 0000000..800b7df --- /dev/null +++ b/database/seeders/RecipeSeeder.php @@ -0,0 +1,17 @@ +count(10)->create(); + } +} From 206a7d873f8094a5e9392cb37b27bfb27107b0b4 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 21 Dec 2023 14:35:28 +0300 Subject: [PATCH 3/7] added recipe author seeder --- database/seeders/RecipeAuthor.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 database/seeders/RecipeAuthor.php diff --git a/database/seeders/RecipeAuthor.php b/database/seeders/RecipeAuthor.php new file mode 100644 index 0000000..58c6319 --- /dev/null +++ b/database/seeders/RecipeAuthor.php @@ -0,0 +1,25 @@ + 0 && Recipe::count() > 0) { + Recipe::each(function ($recipe) { + User::inRandomOrder() + ->first() + ->author_of_recipe() + ->attach($recipe->id); + }); + } + } +} From 11f7bb21886ab51af5e57c3740f04c3dfea92177 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 21 Dec 2023 14:48:25 +0300 Subject: [PATCH 4/7] 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(); + }); + } + } +} From 659f519ff8396fb1d8a5a7e9b0d3d6ceaaf9df9e Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 21 Dec 2023 14:48:44 +0300 Subject: [PATCH 5/7] added recipe seeders to database seeder --- database/seeders/DatabaseSeeder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 4a70195..0fee10b 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -17,7 +17,9 @@ class DatabaseSeeder extends Seeder $this->call(UserSeeder::class); $this->call(PlanAuthor::class); $this->call(PlanCommentSeeder::class); - // $this->call(RecipeSeeder::class); + $this->call(RecipeSeeder::class); + $this->call(RecipeAuthor::class); + $this->call(RecipeCommentSeeder::class); // \App\Models\User::factory(10)->create(); } } From f09986efe4514413542424d2ace0eca0747c8562 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 21 Dec 2023 15:01:03 +0300 Subject: [PATCH 6/7] recipe seeder and factories fix code style --- database/factories/RecipeCommentFactory.php | 4 ++-- database/factories/RecipeFactory.php | 6 ++++-- database/seeders/DatabaseSeeder.php | 10 +++------- database/seeders/RecipeAuthor.php | 4 +++- database/seeders/RecipeCommentSeeder.php | 4 +++- database/seeders/RecipeSeeder.php | 4 +++- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/database/factories/RecipeCommentFactory.php b/database/factories/RecipeCommentFactory.php index 678f38a..bea271f 100644 --- a/database/factories/RecipeCommentFactory.php +++ b/database/factories/RecipeCommentFactory.php @@ -1,5 +1,7 @@ $this->faker->randomDigit(), 'body' => $this->faker->text(), ]; - } } diff --git a/database/factories/RecipeFactory.php b/database/factories/RecipeFactory.php index bc17a8f..edf251e 100644 --- a/database/factories/RecipeFactory.php +++ b/database/factories/RecipeFactory.php @@ -1,5 +1,7 @@ generateSteps(); } @@ -76,7 +78,7 @@ class RecipeFactory extends Factory { $result = []; - for ($i = 0; $i < $count; $i++) { + for ($i = 0; $i < $count; ++$i) { $result[] = $this->generateIngredients(); } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 0fee10b..b4935ee 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -1,17 +1,14 @@ call(PlanSeeder::class); $this->call(UserSeeder::class); @@ -20,6 +17,5 @@ class DatabaseSeeder extends Seeder $this->call(RecipeSeeder::class); $this->call(RecipeAuthor::class); $this->call(RecipeCommentSeeder::class); - // \App\Models\User::factory(10)->create(); } } diff --git a/database/seeders/RecipeAuthor.php b/database/seeders/RecipeAuthor.php index 58c6319..5381a41 100644 --- a/database/seeders/RecipeAuthor.php +++ b/database/seeders/RecipeAuthor.php @@ -1,5 +1,7 @@ 0 && Recipe::count() > 0) { - Recipe::each(function ($recipe) { + Recipe::each(static function ($recipe): void { User::inRandomOrder() ->first() ->author_of_recipe() diff --git a/database/seeders/RecipeCommentSeeder.php b/database/seeders/RecipeCommentSeeder.php index 3b24f5c..eb60093 100644 --- a/database/seeders/RecipeCommentSeeder.php +++ b/database/seeders/RecipeCommentSeeder.php @@ -1,5 +1,7 @@ 0 && Recipe::count() > 0) { $comments = RecipeComment::factory()->count(5)->make(); - $comments->each(function ($comment) { + $comments->each(static function ($comment): void { $comment->author()->associate( User::inRandomOrder() ->first() diff --git a/database/seeders/RecipeSeeder.php b/database/seeders/RecipeSeeder.php index 800b7df..9c4588e 100644 --- a/database/seeders/RecipeSeeder.php +++ b/database/seeders/RecipeSeeder.php @@ -1,9 +1,11 @@ Date: Thu, 21 Dec 2023 17:16:05 +0300 Subject: [PATCH 7/7] added youtube url faker --- composer.json | 1 + composer.lock | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 20adde8..7f1ada7 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "license": "MIT", "require": { "php": "^8.0.2", + "aalaap/faker-youtube": "^2.0", "asantibanez/livewire-charts": "^3.0", "barryvdh/laravel-debugbar": "^3.6", "cyrildewit/eloquent-viewable": "^7.0", diff --git a/composer.lock b/composer.lock index de1d128..5015c72 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,57 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cec18c9498d636695e0fcc9ba3d8ef15", + "content-hash": "f1504229d84c399a1c8aea12005e3530", "packages": [ + { + "name": "aalaap/faker-youtube", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/aalaap/faker-youtube.git", + "reference": "eff2f96ee3f9a845d23140dd1721b14103b5c4d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/aalaap/faker-youtube/zipball/eff2f96ee3f9a845d23140dd1721b14103b5c4d3", + "reference": "eff2f96ee3f9a845d23140dd1721b14103b5c4d3", + "shasum": "" + }, + "require": { + "fakerphp/faker": "^1.10", + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.5.20 || ^8.5.8 || ^9.4.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Faker\\Provider\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "WTFPL" + ], + "authors": [ + { + "name": "Aalaap Ghag", + "email": "aalaap@gmail.com" + } + ], + "description": "Faker provider for generating fake YouTube video URLs", + "keywords": [ + "faker", + "provider", + "youtube" + ], + "support": { + "issues": "https://github.com/aalaap/faker-youtube/issues", + "source": "https://github.com/aalaap/faker-youtube/tree/2.0.3" + }, + "time": "2020-11-07T06:43:34+00:00" + }, { "name": "asantibanez/livewire-charts", "version": "v3.0.1",