diff --git a/composer.json b/composer.json index f93c9ec..3d5d5fb 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 3710b63..7452976 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": "71767f4485e6335b0a9d934fafcfad8e", + "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", diff --git a/database/factories/RecipeCommentFactory.php b/database/factories/RecipeCommentFactory.php new file mode 100644 index 0000000..bea271f --- /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/factories/RecipeFactory.php b/database/factories/RecipeFactory.php new file mode 100644 index 0000000..edf251e --- /dev/null +++ b/database/factories/RecipeFactory.php @@ -0,0 +1,87 @@ + + */ +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; + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 4a70195..b4935ee 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -1,23 +1,21 @@ call(PlanSeeder::class); $this->call(UserSeeder::class); $this->call(PlanAuthor::class); $this->call(PlanCommentSeeder::class); - // $this->call(RecipeSeeder::class); - // \App\Models\User::factory(10)->create(); + $this->call(RecipeSeeder::class); + $this->call(RecipeAuthor::class); + $this->call(RecipeCommentSeeder::class); } } diff --git a/database/seeders/RecipeAuthor.php b/database/seeders/RecipeAuthor.php new file mode 100644 index 0000000..5381a41 --- /dev/null +++ b/database/seeders/RecipeAuthor.php @@ -0,0 +1,27 @@ + 0 && Recipe::count() > 0) { + Recipe::each(static function ($recipe): void { + User::inRandomOrder() + ->first() + ->author_of_recipe() + ->attach($recipe->id); + }); + } + } +} diff --git a/database/seeders/RecipeCommentSeeder.php b/database/seeders/RecipeCommentSeeder.php new file mode 100644 index 0000000..eb60093 --- /dev/null +++ b/database/seeders/RecipeCommentSeeder.php @@ -0,0 +1,39 @@ + 0 && Recipe::count() > 0) { + $comments = RecipeComment::factory()->count(5)->make(); + + $comments->each(static function ($comment): void { + $comment->author()->associate( + User::inRandomOrder() + ->first() + ->id + ); + + $comment->recipe()->associate( + Recipe::inRandomOrder() + ->first() + ->id + ); + + $comment->saveOrFail(); + }); + } + } +} diff --git a/database/seeders/RecipeSeeder.php b/database/seeders/RecipeSeeder.php new file mode 100644 index 0000000..9c4588e --- /dev/null +++ b/database/seeders/RecipeSeeder.php @@ -0,0 +1,19 @@ +count(10)->create(); + } +}