diff --git a/app/Http/Controllers/PlanController.php b/app/Http/Controllers/PlanController.php index 495cb18..474a66f 100644 --- a/app/Http/Controllers/PlanController.php +++ b/app/Http/Controllers/PlanController.php @@ -62,9 +62,13 @@ class PlanController extends Controller ->cooldown($expiresAt) ->record(); - $options1 = $this->unserializeOptions($plan->packet1_options); - $options2 = $this->unserializeOptions($plan->packet2_options); - $options3 = $this->unserializeOptions($plan->packet2_options); + // $options1 = $this->unserializeOptions($plan->packet1_options); + // $options2 = $this->unserializeOptions($plan->packet2_options); + // $options3 = $this->unserializeOptions($plan->packet2_options); + $options1 = $plan->packet1_options; + $options2 = $plan->packet2_options; + $options3 = $plan->packet2_options; + return view('plan/show', [ 'plan' => $plan, diff --git a/app/Livewire/Plan/Create.php b/app/Livewire/Plan/Create.php index fd2ae10..ad02c5d 100644 --- a/app/Livewire/Plan/Create.php +++ b/app/Livewire/Plan/Create.php @@ -27,7 +27,9 @@ class Create extends Component public $packet2_options_input = []; public $packet3_options_input = []; - public $input_items = ""; + public $input_items_1 = ""; + public $input_items_2 = ""; + public $input_items_3 = ""; protected function rules() { @@ -69,41 +71,46 @@ class Create extends Component $this->$options_type['short'] = $this->$options_type_input['short']; $this->$options_type['price'] = $this->$options_type_input['price']; $this->$options_type['description'] = $this->$options_type_input['description']; - $this->$options_type['items'][] = $this->input_items; - $this->reset('input_items'); + $this->$options_type['items'][] = $this->input_items_1; + $this->$options_type['items'][] = $this->input_items_2; + $this->$options_type['items'][] = $this->input_items_3; + $this->reset('input_items_1'); + $this->reset('input_items_2'); + $this->reset('input_items_3'); } public function publish() { - /* dd($this->type); */ $this->validate(); $plan = new Plan(); + $plan->name = $this->name; $plan->image = $this->image->store('plans', 'public'); $plan->duration = $this->duration; $plan->state = $this->state; - $plan->type = json_encode($this->type); $plan->details = $this->details; $plan->packets_count = $this->packets_count; + $plan->type = json_encode($this->type); $plan->packet1_options = json_encode($this->packet1_options); $plan->packet2_options = json_encode($this->packet2_options); $plan->packet3_options = json_encode($this->packet3_options); - $plan->save(); + $plan->saveOrFail(); $user = Auth::user(); $user->author_of_plans()->attach($plan->id); + return redirect()->route('plan.show', $plan->id); } public function addToDrafts() { - $this->type = "draft"; + $this->state = "draft"; $this->publish(); } public function showPreview() { - $this->type = "inactive"; + $this->state = "inactive"; $this->publish(); } } diff --git a/app/Models/Plan.php b/app/Models/Plan.php index 6f81b28..20a25d3 100644 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -1,24 +1,40 @@ 'array', + 'packet1_options' => 'array', + 'packet2_options' => 'array', + 'packet3_options' => 'array', + ]; + + + protected $presenter = PlanPresenter::class; + + public function author() { return $this->belongsToMany(User::class, 'plan_author', 'plan_id', 'user_id'); @@ -48,7 +64,9 @@ class Plan extends Model implements Viewable $result = []; for ($i = 1; $i <= $this->packets_count; $i++) { $key = "packet" . $i . "_options"; - $data = $this->unserializeOptionsObj($this->$key); + + // $data = $this->unserializeOptionsObj($this->$key); + $data = $this->$key; if (!is_null($data)) { $result = array_merge($result, data_get($data, "items", [])); } @@ -59,10 +77,11 @@ class Plan extends Model implements Viewable public function types(): Attribute { - $data = $this->unserializeOptionsArr($this->type); + // $data = $this->unserializeOptionsArr($this->type); + $data = $this->type; return new Attribute( - get: fn() => array_keys($data), + get: fn () => array_keys($data), ); } @@ -71,7 +90,9 @@ class Plan extends Model implements Viewable $result = 0; for ($i = 1; $i <= $this->packets_count; $i++) { $key = "packet" . $i . "_options"; - $data = $this->unserializeOptionsObj($this->$key); + // dd($this->$key); + // $data = $this->unserializeOptionsObj($this->$key); + $data = $this->$key; if (!is_null($data)) { $curPrice = (int)data_get($data, "price", 0); $result = $curPrice > $result ? $curPrice : $result ; @@ -79,7 +100,7 @@ class Plan extends Model implements Viewable } return new Attribute( - get: fn() => $result, + get: fn () => $result, ); } diff --git a/app/Presenters/PlanPresenter.php b/app/Presenters/PlanPresenter.php new file mode 100644 index 0000000..85fcf1e --- /dev/null +++ b/app/Presenters/PlanPresenter.php @@ -0,0 +1,22 @@ +getAuthor(); + + return Storage::url($author->profile_photo_path); + } + + public function getAuthor() + { + return $this->author->first(); + } +} diff --git a/composer.json b/composer.json index c399c19..69c81d6 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,8 @@ "doctrine/dbal": "^3.0", "guzzlehttp/guzzle": "^7.2", "iben12/laravel-statable": "^1.5", + "jzonta/faker-restaurant": "^2.0", + "laracasts/presenter": "^0.2.6", "laravel/framework": "^10.0", "laravel/jetstream": "^4.0", "laravel/sanctum": "^3.2", @@ -59,7 +61,9 @@ ], "post-create-project-cmd": [ "@php artisan key:generate --ansi" - ] + ], + "php-cs-fixer": "php-cs-fixer --config=.php-cs-fixer.php --allow-risky=yes", + "test": "phpunit --colors=always" }, "extra": { "laravel": { diff --git a/composer.lock b/composer.lock index f86d69d..301c7ef 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "34d1a8c89daa6bffe88d41428ab1f92e", + "content-hash": "2e254ae7b37d7841970bf3a2a4f56d80", "packages": [ { "name": "asantibanez/livewire-charts", @@ -1170,6 +1170,74 @@ ], "time": "2023-01-14T14:17:03+00:00" }, + { + "name": "fakerphp/faker", + "version": "v1.23.0", + "source": { + "type": "git", + "url": "https://github.com/FakerPHP/Faker.git", + "reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/e3daa170d00fde61ea7719ef47bb09bb8f1d9b01", + "reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "psr/container": "^1.0 || ^2.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "conflict": { + "fzaninotto/faker": "*" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "doctrine/persistence": "^1.3 || ^2.0", + "ext-intl": "*", + "phpunit/phpunit": "^9.5.26", + "symfony/phpunit-bridge": "^5.4.16" + }, + "suggest": { + "doctrine/orm": "Required to use Faker\\ORM\\Doctrine", + "ext-curl": "Required by Faker\\Provider\\Image to download images.", + "ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.", + "ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.", + "ext-mbstring": "Required for multibyte Unicode string functionality." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "v1.21-dev" + } + }, + "autoload": { + "psr-4": { + "Faker\\": "src/Faker/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "François Zaninotto" + } + ], + "description": "Faker is a PHP library that generates fake data for you.", + "keywords": [ + "data", + "faker", + "fixtures" + ], + "support": { + "issues": "https://github.com/FakerPHP/Faker/issues", + "source": "https://github.com/FakerPHP/Faker/tree/v1.23.0" + }, + "time": "2023-06-12T08:44:38+00:00" + }, { "name": "fruitcake/php-cors", "version": "v1.2.0", @@ -2022,6 +2090,102 @@ ], "time": "2020-06-13T08:05:20+00:00" }, + { + "name": "jzonta/faker-restaurant", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/jzonta/FakerRestaurant.git", + "reference": "4e10ff08dc8ca08603a3daf7abe48d412b013cf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jzonta/FakerRestaurant/zipball/4e10ff08dc8ca08603a3daf7abe48d412b013cf4", + "reference": "4e10ff08dc8ca08603a3daf7abe48d412b013cf4", + "shasum": "" + }, + "require": { + "fakerphp/faker": "^1.9.1", + "php": ">=7.1" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.17", + "phpstan/phpstan": "^0.12.66", + "phpunit/phpunit": "^9" + }, + "type": "library", + "autoload": { + "psr-4": { + "FakerRestaurant\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "João Zonta" + } + ], + "description": "Food and Beverage names generate using fakerphp/faker", + "homepage": "https://github.com/jzonta/FakerRestaurant", + "support": { + "issues": "https://github.com/jzonta/FakerRestaurant/issues", + "source": "https://github.com/jzonta/FakerRestaurant/tree/v2.0.1" + }, + "time": "2021-11-15T11:21:22+00:00" + }, + { + "name": "laracasts/presenter", + "version": "0.2.6", + "source": { + "type": "git", + "url": "https://github.com/laracasts/Presenter.git", + "reference": "4353fb5a1a3b9b9073db66fd823eaaf04c0c5db0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laracasts/Presenter/zipball/4353fb5a1a3b9b9073db66fd823eaaf04c0c5db0", + "reference": "4353fb5a1a3b9b9073db66fd823eaaf04c0c5db0", + "shasum": "" + }, + "require": { + "illuminate/support": "~5.0|~6.0|~7.0|~8.0|^9.0|^10.0", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "~0.9", + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Laracasts\\Presenter": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeffrey Way", + "email": "jeffrey@laracasts.com" + } + ], + "description": "Simple view presenters", + "keywords": [ + "laravel", + "presenter", + "view" + ], + "support": { + "issues": "https://github.com/laracasts/Presenter/issues", + "source": "https://github.com/laracasts/Presenter/tree/0.2.6" + }, + "time": "2023-02-21T16:06:10+00:00" + }, { "name": "laravel/fortify", "version": "v1.17.5", @@ -9324,74 +9488,6 @@ } ], "packages-dev": [ - { - "name": "fakerphp/faker", - "version": "v1.23.0", - "source": { - "type": "git", - "url": "https://github.com/FakerPHP/Faker.git", - "reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/e3daa170d00fde61ea7719ef47bb09bb8f1d9b01", - "reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01", - "shasum": "" - }, - "require": { - "php": "^7.4 || ^8.0", - "psr/container": "^1.0 || ^2.0", - "symfony/deprecation-contracts": "^2.2 || ^3.0" - }, - "conflict": { - "fzaninotto/faker": "*" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.4.1", - "doctrine/persistence": "^1.3 || ^2.0", - "ext-intl": "*", - "phpunit/phpunit": "^9.5.26", - "symfony/phpunit-bridge": "^5.4.16" - }, - "suggest": { - "doctrine/orm": "Required to use Faker\\ORM\\Doctrine", - "ext-curl": "Required by Faker\\Provider\\Image to download images.", - "ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.", - "ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.", - "ext-mbstring": "Required for multibyte Unicode string functionality." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "v1.21-dev" - } - }, - "autoload": { - "psr-4": { - "Faker\\": "src/Faker/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "François Zaninotto" - } - ], - "description": "Faker is a PHP library that generates fake data for you.", - "keywords": [ - "data", - "faker", - "fixtures" - ], - "support": { - "issues": "https://github.com/FakerPHP/Faker/issues", - "source": "https://github.com/FakerPHP/Faker/tree/v1.23.0" - }, - "time": "2023-06-12T08:44:38+00:00" - }, { "name": "filp/whoops", "version": "2.15.3", diff --git a/database/factories/PlanFactory.php b/database/factories/PlanFactory.php new file mode 100755 index 0000000..a87d4b4 --- /dev/null +++ b/database/factories/PlanFactory.php @@ -0,0 +1,58 @@ + + */ +class PlanFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + + $faker = \Faker\Factory::create(); + $this->faker->addProvider(new Restaurant($faker)); + + $typeBody = [ + 'fit' => $this->faker->boolean(), + 'slim' => $this->faker->boolean(), + 'behavior' => $this->faker->boolean(), + 'wellness' => $this->faker->boolean(), + ]; + + $packetsOptions = [ + 'items' => [$this->faker->fruitName(), $this->faker->meatName(), $this->faker->sauceName()], + 'price' => $this->faker->randomNumber(), + 'short' => $this->faker->foodName(), + 'description' => $this->faker->text(), + ]; + + Storage::fake('plans'); + $file = UploadedFile::fake()->image('plan.png'); + $fileLocalPath = $file->store('plans', 'public'); + + return [ + 'name' => $this->faker->foodName(), + // 'image' => UploadedFile::fake()->image('plans/Photo_C.png'), + 'image' => $fileLocalPath, + 'duration' => $this->faker->randomElement([7, 14,21]), + 'state' => $this->faker->randomElement(['active', 'draft', 'archived']), + 'type' => $typeBody, + 'details' => $this->faker->text(), + 'packets_count' => $this->faker->randomElement([1, 3]), + 'packet1_options' => $packetsOptions, + 'packet2_options' => $packetsOptions, + 'packet3_options' => $packetsOptions, + ]; + } +} diff --git a/database/factories/UserDetailzFactory.php b/database/factories/UserDetailzFactory.php index a17eaa8..bf91c8f 100644 --- a/database/factories/UserDetailzFactory.php +++ b/database/factories/UserDetailzFactory.php @@ -21,7 +21,7 @@ class UserDetailzFactory extends Factory public function definition() { return [ - 'user_id' => User::factory(), + // 'user_id' => User::factory(), 'first_name' => $this->faker->name(), 'last_name' => $this->faker->name(), 'birthdate' => $this->faker->date('Y-m-d'), @@ -43,6 +43,8 @@ class UserDetailzFactory extends Factory 'favorite_foods' => $this->faker->text(), 'unfavorite_foods' => $this->faker->text(), 'additional_info' => $this->faker->text(), + 'is_mood_fillable' => $this->faker->boolean(), + 'is_bedtime_fillable' => $this->faker->boolean(), ]; } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 46cb47d..79728fe 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -20,6 +20,8 @@ class UserFactory extends Factory */ public function definition(): array { + + return [ 'name' => $this->faker->name(), 'email' => $this->faker->unique()->safeEmail(), diff --git a/database/migrations/2022_03_31_093623_create_user_detailzs_table.php b/database/migrations/2022_03_31_093623_create_user_detailzs_table.php index 51369ec..5034343 100644 --- a/database/migrations/2022_03_31_093623_create_user_detailzs_table.php +++ b/database/migrations/2022_03_31_093623_create_user_detailzs_table.php @@ -16,7 +16,7 @@ return new class extends Migration { Schema::create('user_detailzs', function (Blueprint $table) { $table->id(); - $table->bigInteger('user_id'); + $table->bigInteger('user_id')->nullable(); $table->string('first_name', 256)->default(''); $table->string('last_name', 256)->default(''); $table->date('birthdate')->default('1980-01-01')->nullable(false); diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 71f673f..a8222ee 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -14,6 +14,8 @@ class DatabaseSeeder extends Seeder */ public function run() { + $this->call(PlanSeeder::class); + $this->call(UserSeeder::class); // \App\Models\User::factory(10)->create(); } } diff --git a/database/seeders/PlanAuthor.php b/database/seeders/PlanAuthor.php new file mode 100644 index 0000000..805280a --- /dev/null +++ b/database/seeders/PlanAuthor.php @@ -0,0 +1,27 @@ + 0 && Plan::count() > 0) { + Plan::each( function ($plan) { + User::inRandomOrder() + ->first() + ->author_of_plans() + ->attach($plan->id); + }); + } + } +} diff --git a/database/seeders/PlanSeeder.php b/database/seeders/PlanSeeder.php new file mode 100755 index 0000000..81cf277 --- /dev/null +++ b/database/seeders/PlanSeeder.php @@ -0,0 +1,19 @@ +count(10)->create(); + } +} diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php new file mode 100644 index 0000000..e2fc86c --- /dev/null +++ b/database/seeders/UserSeeder.php @@ -0,0 +1,62 @@ +create(); + + $userDetailz = UserDetailz::factory()->make(); + + $userDetailz->user()->associate($user); + + $userDetailz->saveOrFail(); + + }, $this->getListUsers()); + } + + private function getListUsers(): array + { + $allUsersHash = Hash::make('1234567890'); + + return [ + ['id' => 3, 'name' => 'Анчоус Альф', 'email' => 'reshetnick.mike+user1@gmail.com', 'password' => $allUsersHash, 'is_consultant' => true], + ['id' => 4, 'name' => 'Чена Сибаину', 'email' => 'reshetnik.n+user1@gmail.com', 'password' => $allUsersHash, 'is_consultant' => true], + ['id' => 5, 'name' => 'Бруно Бармалей', 'email' => 'reshetnick.mike+user2@gmail.com', 'password' => $allUsersHash, 'is_consultant' => true], + ['id' => 6, 'name' => 'Варенник Васаби', 'email' => 'reshetnick.mike+user3@gmail.com', 'password' => $allUsersHash, 'is_consultant' => true], + ['id' => 7, 'name' => 'Денди Дуглас', 'email' => 'reshetnick.mike+user4@gmail.com', 'password' => $allUsersHash, 'is_consultant' => true], + ['id' => 8, 'name' => 'Ник Радченков', 'email' => 'reshetnik.n+user2@gmail.com', 'password' => $allUsersHash], + ['id' => 9, 'name' => 'Миса Кошка', 'email' => 'reshetnik.n+user3@gmail.com', 'password' => $allUsersHash], + + ['id' => 10, 'name' => 'Ерошка Есаул', 'email' => 'reshetnick.mike+user5@gmail.com', 'password' => $allUsersHash], + ['id' => 11, 'name' => 'Жмурка Живчик', 'email' => 'reshetnick.mike+user6@gmail.com', 'password' => $allUsersHash], + ['id' => 12, 'name' => 'Гошка Картошка', 'email' => 'reshetnik.n+user4@gmail.com', 'password' => $allUsersHash], + ['id' => 13, 'name' => 'Зефир Забияка', 'email' => 'reshetnick.mike+user7@gmail.com', 'password' => $allUsersHash], + ['id' => 14, 'name' => 'Антоша Одуван', 'email' => 'reshetnik.n+user5@gmail.com', 'password' => $allUsersHash], + ['id' => 15, 'name' => 'Кусик Кукусик', 'email' => 'reshetnik.n+user6@gmail.com', 'password' => $allUsersHash], + ['id' => 16, 'name' => 'Косик Кокосик', 'email' => 'reshetnik.n+user7@gmail.com', 'password' => $allUsersHash], + + ['id' => 17, 'name' => 'Хинкалька Вкусная', 'email' => 'reshetnik.n+user8@gmail.com', 'password' => $allUsersHash], + ['id' => 18, 'name' => 'Импульс Йети', 'email' => 'reshetnick.mike+user8@gmail.com', 'password' => $allUsersHash], + ['id' => 19, 'name' => 'Квики Кекс', 'email' => 'reshetnick.mike+user9@gmail.com', 'password' => $allUsersHash], + ['id' => 20, 'name' => 'Чебурек Сочный', 'email' => 'reshetnik.n+user9@gmail.com', 'password' => $allUsersHash], + ['id' => 21, 'name' => 'Клубника Дикая', 'email' => 'reshetnik.n+user10@gmail.com', 'password' => $allUsersHash], + ['id' => 22, 'name' => 'Ляпис Лапша', 'email' => 'reshetnick.mike+user10@gmail.com', 'password' => $allUsersHash], + ['id' => 23, 'name' => 'Друг Парадоксов', 'email' => 'reshetnick.mike+user11@gmail.com', 'password' => $allUsersHash], + ]; + } +} diff --git a/resources/views/livewire/plan/create.blade.php b/resources/views/livewire/plan/create.blade.php index d174a7b..a3f8d55 100644 --- a/resources/views/livewire/plan/create.blade.php +++ b/resources/views/livewire/plan/create.blade.php @@ -1,92 +1,190 @@ -
-
- Мои планы -
-
Добавление плана
-
-
-
+
+
+
+ +

+ Мои планы +

+
-
+
+
+
+ Название +
+ +
-
-
- - -
+
+
+
+
+ Изображение +
+
+
+
-
- -
+
+ Описание +
+ +
+
+ -
- - @isset($packet1_options['items']) -
    - @foreach($packet1_options['items'] as $item) -
  • - {{ $item }} -
  • - @endforeach -
- @endisset -
-
- -
-
- -
-
-
- @endif - - @if($packets_count === 3) -
-
-
-
- - -
-
- - -
-
-
- - -
- - @isset($packet1_options['items']) -
    - @foreach($packet1_options['items'] as $item) -
  • - {{ $item }} -
  • - @endforeach -
- @endisset -
-
- -
-
- -
-
-
-
-
-
- - -
-
- - -
-
-
- - -
- - @isset($packet2_options['items']) -
    - @foreach($packet2_options['items'] as $item) -
  • - {{ $item }} -
  • - @endforeach -
- @endisset -
-
- -
-
- -
-
-
-
-
-
- - -
-
- - -
-
-
- - -
- - @isset($packet3_options['items']) -
    - @foreach($packet3_options['items'] as $item) -
  • - {{ $item }} -
  • - @endforeach -
- @endisset -
-
- -
-
- -
+ .catch(error => { + console.error(error); + });" wire:key="myIdentifierHere" + x-ref="myIdentifierHere" wire:model="details"> +
-
+
+ + + +
+
+
+ ОКАЗАНИЕ УСЛУГ +
+
+ + +
+
+ + @if ($packets_count === 1) +
+
+
+
+
+
+ Краткое описание +
+ +
+
+
+ Цена +
+ +
+
+
+
+
+ Описание услуги: +
+ +
+
+ +
+
+
+ Содержание услуги +
+ @isset($packet1_options['items']) +
    + @foreach ($packet1_options['items'] as $item) +
  • + {{ $item }} +
  • + @endforeach +
+ @endisset +
+
+ +
+
+ +
+ +
+
+
+
+
+ @endif + +
+ + @if ($packets_count === 3) + + +
+
+
+
+
+
+ Краткое описание +
+ +
+
+
+ Цена + + + 1 вариант + +
+ +
+
+
+
+
+ Описание услуги: +
+ +
+
+ +
+
+
+ Содержание услуги +
+ @isset($packet1_options['items']) +
    + @foreach ($packet1_options['items'] as $item) +
  • + {{ $item }} +
  • + @endforeach +
+ @endisset +
+
+ +
+
+ +
+ +
+
+
+
+
+ + + +
+
+
+
+
+
+ Краткое описание +
+ +
+
+
+ Цена + + + 2 вариант + +
+ +
+
+
+
+
+ Описание услуги: +
+ +
+
+ +
+
+
+ Содержание услуги +
+ @isset($packet2_options['items']) +
    + @foreach ($packet2_options['items'] as $item) +
  • + {{ $item }} +
  • + @endforeach +
+ @endisset +
+
+ +
+
+ +
+ +
+
+
+
+
+ + + +
+
+
+
+
+
+ Краткое описание +
+ +
+
+
+ Цена + + + 3 вариант + +
+ +
+
+
+
+
+ Описание услуги: +
+ +
+
+ +
+
+
+ Содержание услуги +
+ @isset($packet3_options['items']) +
    + @foreach ($packet3_options['items'] as $item) +
  • + {{ $item }} +
  • + @endforeach +
+ @endisset +
+
+ +
+
+ +
+ +
+
+
+
+
@endif -
- @if($errors) -
-
    - @foreach($errors->all() as $message) -
  • {{ $message }}
  • - @endforeach -
+ + @if ($errors) +
+
    + @foreach ($errors->all() as $message) +
  • {{ $message }}
  • + @endforeach +
+
+ @endif + + +
+ + + +
+
- @endif - -
-
- - -
- -
-
-
- - -
diff --git a/resources/views/plan/index.blade.php b/resources/views/plan/index.blade.php index 14803f2..c0790fe 100644 --- a/resources/views/plan/index.blade.php +++ b/resources/views/plan/index.blade.php @@ -49,7 +49,7 @@ @php - $author = $plan->author()->first(); + $author = $plan->present()->getAuthor; @endphp diff --git a/resources/views/plan/show.blade.php b/resources/views/plan/show.blade.php index 29a1f2d..ca3913f 100644 --- a/resources/views/plan/show.blade.php +++ b/resources/views/plan/show.blade.php @@ -1,7 +1,10 @@ @extends('layouts/eatvio') @php - $author = $plan->author()->first(); - $authorPhoto = Storage::url($author->profile_photo_path); + + $author = $plan->present()->getAuthor; + + $authorPhoto = $plan->present()->getAuthorPhoto; + $image = Storage::url($plan->image); $planViewsCount = views($plan)->unique()->count(); @endphp diff --git a/tests/Feature/Plan/CreateTest.php b/tests/Feature/Plan/CreateTest.php new file mode 100644 index 0000000..ce132e2 --- /dev/null +++ b/tests/Feature/Plan/CreateTest.php @@ -0,0 +1,134 @@ +image = UploadedFile::fake()->image('plan.png'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->plan = Plan::factory()->make(); + + } + + public function test_show_form_create_plan() + { + $response = $this->actingAs($this->user) + ->get('/plan/create'); + + $response + ->assertStatus(302) + ->assertRedirect('https://dev2.eatvio.com/ru'); + } + + public function test_publish_new_plan_success(): void + { + $countPlanBeforeCreated = $this->plan->count(); + + $this->actingAs($this->user); + + Livewire::test(Create::class) + ->set('name', $this->plan->name) + ->assertSet('name', $this->plan->name) + ->set('image', $this->image) + ->set('duration', $this->plan->duration) + ->set('state', $this->plan->state) + ->set('type', $this->plan->type) + ->set('details', $this->plan->details) + ->set('packets_count', $this->plan->packets_count) + ->set('packet1_options', $this->plan->packet1_options) + ->set('packet2_options', $this->plan->packet2_options) + ->set('packet3_options', $this->plan->packet3_options) + ->call('publish') + // ->assertFileDownloaded('plan.png'); + ->assertStatus(200) + ->assertRedirect('plan/'.$this->plan->count()); + + $countPlanAfterCreated = $this->plan->count(); + + + $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); + } +// + public function test_to_draft_new_plan_success(): void + { + $countPlanBeforeCreated = $this->plan->count(); + + $this->actingAs($this->user); + + Livewire::test(Create::class) + ->set('name', $this->plan->name) + ->assertSet('name', $this->plan->name) + ->set('image', $this->image) + ->set('duration', $this->plan->duration) + ->set('state', $this->plan->state) + ->set('type', $this->plan->type) + ->set('details', $this->plan->details) + ->set('packets_count', $this->plan->packets_count) + ->set('packet1_options', $this->plan->packet1_options) + ->set('packet2_options', $this->plan->packet2_options) + ->set('packet3_options', $this->plan->packet3_options) + ->call('addToDrafts') + // ->assertFileDownloaded('plan.png'); + ->assertStatus(200) + ->assertRedirect('plan/'.$this->plan->count()); + + $countPlanAfterCreated = $this->plan->count(); + + $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); + } +// + public function test_to_preview_new_plan_success(): void + { + + $countPlanBeforeCreated = $this->plan->count(); + + $this->actingAs($this->user); + + Livewire::test(Create::class) + ->set('name', $this->plan->name) + ->assertSet('name', $this->plan->name) + ->set('image', $this->image) + ->set('duration', $this->plan->duration) + ->set('state', $this->plan->state) + ->set('type', $this->plan->type) + ->set('details', $this->plan->details) + ->set('packets_count', $this->plan->packets_count) + ->set('packet1_options', $this->plan->packet1_options) + ->set('packet2_options', $this->plan->packet2_options) + ->set('packet3_options', $this->plan->packet3_options) + ->call('showPreview') + // ->assertFileDownloaded('plan.png'); + ->assertStatus(200) + ->assertRedirect('plan/'.$this->plan->count()); + + $countPlanAfterCreated = $this->plan->count(); + + $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); + } + +}