diff --git a/app/Livewire/Recipe/Comment/Create.php b/app/Livewire/Recipe/Comment/Create.php index 6541c37..e0a0aff 100644 --- a/app/Livewire/Recipe/Comment/Create.php +++ b/app/Livewire/Recipe/Comment/Create.php @@ -17,13 +17,25 @@ class Create extends Component public $grade = 0; + public $isChecked = false; + public function render() { return view('livewire.recipe.comment.create'); } + public function toggle() + { + $this->isChecked = !$this->isChecked; + } + public function save() { + $this->validate([ + 'body' => 'required|min:3', + 'grade' => 'required', + ]); + $comment = new RecipeComment(); $comment->grade = $this->grade; $comment->body = $this->body; @@ -32,6 +44,9 @@ class Create extends Component $comment->save(); $this->reset(['body', 'grade']); + + $this->toggle(); + $this->dispatch('commentAdded')->to('recipe.comment.show'); } } diff --git a/app/Livewire/Recipe/Comment/Show.php b/app/Livewire/Recipe/Comment/Show.php index e38077f..ca2278f 100644 --- a/app/Livewire/Recipe/Comment/Show.php +++ b/app/Livewire/Recipe/Comment/Show.php @@ -9,10 +9,19 @@ class Show extends Component { public Recipe $recipe; + public array $tabpanelState = ['positive' => 'positive', 'negative' => false]; + protected $listeners = ['commentAdded' => '$refresh']; public function render() { return view('livewire.recipe.comment.show'); } + + public function toggleTabpanelState($tabpanelName) + { + collect($this->tabpanelState)->keys()->map(fn($key) => $key === $tabpanelName + ? $this->tabpanelState[$tabpanelName] = $tabpanelName + : $this->tabpanelState[$key] = false, array_keys($this->tabpanelState)); + } } diff --git a/app/Livewire/Recipe/Create.php b/app/Livewire/Recipe/Create.php index 65cf6a3..a1d1c51 100644 --- a/app/Livewire/Recipe/Create.php +++ b/app/Livewire/Recipe/Create.php @@ -17,6 +17,10 @@ class Create extends Component public $state = 'active'; + public $state_ingredient = 'active'; + + public $state_article = 'active'; + public $tags = []; public $title; @@ -39,20 +43,21 @@ class Create extends Component public $ingredients_unit = 'gr'; + public $state_row = ['ingredient' => 'true', 'article' => 'false']; + protected $listeners = ['stepRemoved' => '$refresh']; - public function render() + + + public function toggleStateRow(string $currentRow): void { - return view('livewire.recipe.create'); + collect($this->state_row)->keys()->map(fn($key) => $key === $currentRow + ? $this->state_row[$currentRow] = 'true' + : $this->state_row[$key] = 'false'); } public function addIngredient(): void { - // dd( - // $this->ingredients_name, - // $this->ingredients_portion, - // $this->ingredients_unit - // ); $this->ingredients[] = [ 'name' => $this->ingredients_name, 'portion' => $this->ingredients_portion, @@ -99,7 +104,7 @@ class Create extends Component public function parentComponentTagRemoved($tag) { $this->tags = collect($this->tags) - ->filter(fn ($curTag) => $curTag['name'] !== $tag) + ->filter(fn($curTag) => $curTag['name'] !== $tag) ->all(); } @@ -117,9 +122,21 @@ class Create extends Component $this->publish(); } + protected function rules() + { + return [ + 'image' => 'required|image|max:2048', + 'state' => 'required|in:active,archived', + 'description' => 'required|min:3', + 'type' => 'required|min:3', + 'video_url' => 'nullable|url|max:2048', + 'cooking_time' => 'nullable|numeric', + ]; + } + public function publish() { - // dd($this->description); + $this->validate(); $recipe = new Recipe(); @@ -134,7 +151,7 @@ class Create extends Component $recipe->ingredients = $this->ingredients; $recipe->save(); - $tagsIds = collect($this->tags)->map(fn ($curTag) => $curTag['id']); + $tagsIds = collect($this->tags)->map(fn($curTag) => $curTag['id']); $recipe->tags()->attach($tagsIds); $user = Auth::user(); @@ -143,19 +160,6 @@ class Create extends Component return redirect()->route('recipe.show', $recipe->id); } - protected function rules() - { - return [ - 'image' => 'required|image|max:2048', - 'state' => 'required|in:active,archived', - 'description' => 'required|min:3', - 'type' => 'required|min:3', - 'video_url' => 'nullable|url|max:2048', - 'cooking_time' => 'nullable|numeric', - - ]; - } - private function transformSteps($steps) { return collect($steps)->map( @@ -163,7 +167,7 @@ class Create extends Component if (gettype($step['image']) === 'string') { $data['image'] = $step['image']; } else { - $data['image'] = ! is_null($step['image']) ? $step['image']->store('steps', 'public') : ''; + $data['image'] = !is_null($step['image']) ? $step['image']->store('steps', 'public') : ''; } $data['description'] = $step['description']; @@ -173,8 +177,11 @@ class Create extends Component )->toArray(); } - // public function updated($property) - // { - // dd($property, $this->$property); - // } + + public function render() + { + return view('livewire.recipe.create'); + } + + } diff --git a/app/Livewire/Recipe/Edit.php b/app/Livewire/Recipe/Edit.php index 001f695..928b244 100644 --- a/app/Livewire/Recipe/Edit.php +++ b/app/Livewire/Recipe/Edit.php @@ -17,6 +17,10 @@ class Edit extends Component public $state = 'active'; + public $state_ingredient = 'active'; + + public $state_article = 'active'; + public $type = 'other'; public $tags; @@ -39,6 +43,8 @@ class Edit extends Component public $ingredients_unit = 'gr'; + public $state_row = ['ingredient' => 'true', 'article' => 'false']; + protected $listeners = ['stepRemoved' => '$refresh', 'parentComponentTagAdded', 'parentComponentTagRemoved']; public function mount(Recipe $recipe) @@ -56,14 +62,15 @@ class Edit extends Component $this->video_url = $recipe->video_url; } - public function render() + public function toggleStateRow(string $currentRow): void { - return view('livewire.recipe.edit'); + collect($this->state_row)->keys()->map(fn($key) => $key === $currentRow + ? $this->state_row[$currentRow] = 'true' + : $this->state_row[$key] = 'false'); } public function addIngredient() { - // $this->ingredients[] = ['name' => '', 'portion' => '']; $this->ingredients[] = [ 'name' => $this->ingredients_name, 'portion' => $this->ingredients_portion, @@ -115,6 +122,19 @@ class Edit extends Component $this->recipe->tags()->detach($selectedTags); } + protected function rules() + { + return [ + 'image' => 'filled', + 'state' => 'required|in:active,archived', + 'description' => 'required|min:3', + 'type' => 'required|min:3', + 'video_url' => 'nullable|url|max:2048', + 'cooking_time' => 'nullable|numeric', + ]; + } + + public function draft() { $this->state = 'archived'; @@ -150,18 +170,6 @@ class Edit extends Component return redirect()->route('recipe.show', $recipe->id); } - protected function rules() - { - return [ - 'image' => 'filled', - 'state' => 'required|in:active,archived', - 'description' => 'required|min:3', - 'type' => 'required|min:3', - 'video_url' => 'nullable|url|max:2048', - 'cooking_time' => 'nullable|numeric', - ]; - } - private function transformSteps($steps) { return collect($steps)-> @@ -176,4 +184,11 @@ class Edit extends Component return $data; })->toArray(); } + + + public function render() + { + return view('livewire.recipe.edit'); + } + } diff --git a/app/Models/Plan.php b/app/Models/Plan.php index c9b3bf1..2167a42 100644 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -134,12 +134,12 @@ class Plan extends Model implements Viewable return false; } - public function scopeByNegative(Builder $query) + public function scopeNegativeComments(Builder $query) { return static::comments()->where('grade', '<=', '3'); } - public function scopeByPositive(Builder $query) + public function scopePositiveComments(Builder $query) { return static::comments()->where('grade', '>', '3'); } diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php old mode 100644 new mode 100755 index beffe35..b7250ff --- a/app/Models/Recipe.php +++ b/app/Models/Recipe.php @@ -8,10 +8,15 @@ use Illuminate\Database\Eloquent\Casts\AsCollection; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Contracts\Database\Eloquent\Builder; +use Spatie\Sluggable\HasSlug; +use Spatie\Sluggable\SlugOptions; class Recipe extends Model implements Viewable { - use HasFactory, InteractsWithViews; + use HasFactory; + use InteractsWithViews; + use HasSlug; protected $casts = [ 'steps' => AsCollection::class, @@ -23,6 +28,27 @@ class Recipe extends Model implements Viewable 'comments', ]; + public function getSlugOptions(): SlugOptions + { + return SlugOptions::create() + ->generateSlugsFrom(['title']) + ->saveSlugsTo('slug') + // ->slugsShouldBeNoLongerThan(20) + ->usingSeparator('_'); + // ->usingLanguage('ru') + // ->doNotGenerateSlugsOnUpdate(); + } + + /** + * Get the route key for the model. + * + * @return string + */ + public function getRouteKeyName() + { + return 'slug'; + } + public function tags() { return $this->morphToMany(Tag::class, 'taggable'); @@ -56,6 +82,17 @@ class Recipe extends Model implements Viewable return $this->hasMany(RecipeLike::class); } + + public function scopeNegativeComments(Builder $query) + { + return static::comments()->where('grade', '<=', '3'); + } + + public function scopePositiveComments(Builder $query) + { + return static::comments()->where('grade', '>', '3'); + } + public function isLiked(): bool { $curUser = auth()->user(); diff --git a/composer.lock b/composer.lock index 7452976..1bf3663 100644 --- a/composer.lock +++ b/composer.lock @@ -13868,3 +13868,4 @@ "platform-dev": [], "plugin-api-version": "2.6.0" } + diff --git a/database/factories/TagFactory.php b/database/factories/TagFactory.php new file mode 100644 index 0000000..5bb5ba1 --- /dev/null +++ b/database/factories/TagFactory.php @@ -0,0 +1,28 @@ + + */ +class TagFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + $faker = \Faker\Factory::create(); + $this->faker->addProvider(new Restaurant($faker)); + return [ + 'name' => $this->faker->foodName(), + ]; + } +} diff --git a/database/migrations/2023_12_25_123200_add_slug_to_recipe.php b/database/migrations/2023_12_25_123200_add_slug_to_recipe.php new file mode 100644 index 0000000..0b3b89f --- /dev/null +++ b/database/migrations/2023_12_25_123200_add_slug_to_recipe.php @@ -0,0 +1,28 @@ +string('slug'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('recipes', function (Blueprint $table) { + $table->dropColumn('slug'); + }); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index b4935ee..0be680a 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -17,5 +17,6 @@ class DatabaseSeeder extends Seeder $this->call(RecipeSeeder::class); $this->call(RecipeAuthor::class); $this->call(RecipeCommentSeeder::class); + $this->call(RecipeTagSeeder::class); } } diff --git a/database/seeders/RecipeTagSeeder.php b/database/seeders/RecipeTagSeeder.php new file mode 100644 index 0000000..e78ed35 --- /dev/null +++ b/database/seeders/RecipeTagSeeder.php @@ -0,0 +1,30 @@ + 0) { + $recipes = Recipe::all(); + + $recipes->each(static function ($recipe): void { + + $tags = Tag::factory()->count(5)->create(); + + $tagsIds = collect($tags)->map(fn($curTag) => $curTag['id']); + $recipe->tags()->attach($tagsIds); + }); + } + } +} diff --git a/resources/css/app.css b/resources/css/app.css index a827885..fe60da7 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -21,3 +21,12 @@ .active-icon-heart{ color: #2f80ed; } + + /* Recipe-show like */ +.text-blue-400 { color: #2f80ed; } + +.text-blue-500 { color: #2f80ed;} + +.text-gray-400 { color: #cbd5e0; } + +.text-gray-500 { color: #a0aec0; } diff --git a/resources/views/livewire/plan/comment/show.blade.php b/resources/views/livewire/plan/comment/show.blade.php index 5282a0a..504e478 100644 --- a/resources/views/livewire/plan/comment/show.blade.php +++ b/resources/views/livewire/plan/comment/show.blade.php @@ -1,8 +1,8 @@
@php - $positivComments = $plan->byPositive(); + $positivComments = $plan->positiveComments(); - $negativeComments = $plan->byNegative(); + $negativeComments = $plan->negativeComments(); $positiveCommmentsCount = $positivComments->count(); diff --git a/resources/views/livewire/recipe/comment/create.blade.php b/resources/views/livewire/recipe/comment/create.blade.php index 8873d7e..727b68f 100644 --- a/resources/views/livewire/recipe/comment/create.blade.php +++ b/resources/views/livewire/recipe/comment/create.blade.php @@ -1,24 +1,46 @@ -
-
- -
- - $grade >= 1]) width="24" height="24"> - - - $grade >= 2]) width="24" height="24"> - - - $grade >= 3]) width="24" height="24"> - - - $grade >= 4]) width="24" height="24"> - - - $grade >= 5]) width="24" height="24"> - +
+
+ +
+
+ $isChecked]) wire:model="isChecked" wire:click="$set('grade', 5)" type="radio" + name="rate" id="rate-5" value="5" hidden> + + $isChecked]) wire:model="isChecked" wire:click="$set('grade',4)" type="radio" + name="rate" id="rate-4" value="4" hidden> + + $isChecked]) wire:model="isChecked" wire:click="$set('grade',3)" type="radio" + name="rate" id="rate-3" value="3" hidden> + + $isChecked]) wire:model="isChecked" wire:click="$set('grade',2)" type="radio" + name="rate" id="rate-2" value="2" hidden> + + $isChecked]) wire:model="isChecked" wire:click="$set('grade',1)" type="radio" + name="rate" id="rate-1" value="1" hidden> + + +
+ -
-
+ + + + + @error('grade') +
+ {{ $message }} +
+ @enderror + + + + @error('body') +
+ {{ $message }} +
+ @enderror + +
diff --git a/resources/views/livewire/recipe/comment/show.blade.php b/resources/views/livewire/recipe/comment/show.blade.php index 361bc41..8573f9b 100644 --- a/resources/views/livewire/recipe/comment/show.blade.php +++ b/resources/views/livewire/recipe/comment/show.blade.php @@ -1,60 +1,84 @@ -
-
комментарии
+
@php - $positivComments = $recipe->comments()->where('grade', '>', '3'); - $negativeComments = $recipe->comments()->where('grade', '<=', '3'); - $positiveCommmentsCount = $positivComments->count(); - $negativeCommentsCount = $negativeComments->count(); - @endphp - -
-
- @foreach($positivComments->get() as $comment) -
-
- -
- {{ $comment->author->name }} - {{ $comment->body }} + $positivComments = $recipe->positiveComments(); + $negativeComments = $recipe->negativeComments(); + + $positiveCommmentsCount = $positivComments->count(); + + $negativeCommentsCount = $negativeComments->count(); + + @endphp + +
+
+ + +
+ +
$tabpanelState['negative'] + ]) role="tabpanel" id="tabpanel-1" tabindex="0" aria-labelledby="tab-1"> + @foreach ($positivComments->get() as $comment) +
+
+
+ user
-
-
-
- - {{ $comment->grade }} +
+
+ {{ $comment->author->name }} +
+
+ {{ $comment->body }} +
+
+
+
+ {{ $comment->grade }} +
+
- @livewire('recipe.comment.upvote', ['comment' => $comment])
@endforeach
-
- @foreach($negativeComments->get() as $comment) -
-
- -
- {{ $comment->author->name }} - {{ $comment->body }} + + +
$tabpanelState['positive'] + ]) role="tabpanel" id="tabpanel-2" tabindex="0" aria-labelledby="tab-1"> + @foreach ($negativeComments->get() as $comment) +
+
+
+ user
-
-
-
- - {{ $comment->grade }} +
+
+ {{ $comment->author->name }} +
+
+ {{ $comment->body }} +
+
+
+
+ {{ $comment->grade }} +
+ +
- @livewire('recipe.comment.upvote', ['comment' => $comment])
@endforeach
+
+
diff --git a/resources/views/livewire/recipe/comment/upvote.blade.php b/resources/views/livewire/recipe/comment/upvote.blade.php index 9286173..6dcc9d6 100644 --- a/resources/views/livewire/recipe/comment/upvote.blade.php +++ b/resources/views/livewire/recipe/comment/upvote.blade.php @@ -1,4 +1,4 @@ -
id }}> +
id }}> diff --git a/resources/views/livewire/recipe/create.blade.php b/resources/views/livewire/recipe/create.blade.php index 397206f..11732a8 100644 --- a/resources/views/livewire/recipe/create.blade.php +++ b/resources/views/livewire/recipe/create.blade.php @@ -1,11 +1,11 @@
-
+
- Мой блог + Мой блог

{{ __('recipe.adding') }}

-
+
{{ __('recipe.title') }}
@@ -24,53 +24,82 @@
-
-
-
{{ __('recipe.picture') }}
-
@php $stepsCount = count($steps); @endphp - @for($i = 0; $i < $stepsCount; $i++) -
-
- {{ __('recipe.step') }} {{ $i + 1 }} - @if($i == 0) - {{ __('recipe.total_steps') }}: {{ $stepsCount }} - @endif -
-
- - -
- - + @for ($i = 0; $i < $stepsCount; $i++) +
+
+ {{ __('recipe.step') }} {{ $i + 1 }} + @if ($i == 0) + {{ __('recipe.total_steps') }}: {{ $stepsCount }} + @endif +
+
+ + +
+ + +
+
-
-
@endfor
-
{{ __('recipe.tags') }}
- - +
{{ __('recipe.tags') }}
+ +
-
{{ __('recipe.video_link') }}
- +
{{ __('recipe.video_link') }}
+
-
+
{{--
@@ -259,7 +332,7 @@
@php $lastIngedient = count($ingredients) - 1; @endphp - @foreach($ingredients as $k => $ingredient) + @foreach ($ingredients as $k => $ingredient)
@@ -303,9 +376,12 @@
--}}
- - - + + +
@@ -315,4 +391,3 @@ @endforeach
- diff --git a/resources/views/livewire/recipe/edit.blade.php b/resources/views/livewire/recipe/edit.blade.php index 13fee5f..42e9112 100644 --- a/resources/views/livewire/recipe/edit.blade.php +++ b/resources/views/livewire/recipe/edit.blade.php @@ -26,197 +26,279 @@
-
-
{{ __('recipe.picture') }}
- - @error('image') {{ $message }} @enderror -
-
-
-
- Тип записи -
-
- - -
-
-
-
+
{{ __('recipe.picture') }}
+ + @error('image') + {{ $message }} + @enderror +
+
-
{{ __('recipe.cooking_time') }}
- -
-
-
-
{{ __('recipe.record_state') }}
- -
-
- @php $n = count($ingredients); $lastIngedient = $n-1; @endphp - @if($n == 0) -
-
-
- -
-
-
+
+ + +
+ + {{--
--}} + {{-- --}} + {{-- --}} + {{--
--}} + +
+
+
$state_row['ingredient'] !== 'true', + ]) role="tabpanel" id="tabpanel-1" tabindex="0" + aria-labelledby="tab-1"> +
+
+
{{ __('recipe.cooking_time') }}
+ +
+
+
+
+
{{ __('recipe.record_state') }}
+ +
+
+ @php + $n = count($ingredients); + $lastIngedient = $n - 1; + @endphp + @if ($n == 0) +
+
+
+ +
- -
+
+
+ +
+ +
+ + +
+
+
+
+
+ @endif + @foreach ($ingredients as $k => $ingredient) +
+
+
+ +
- - +
+
+ +
+
+ + @if ($k == count($ingredients) - 1) + + @endif +
+ +
-
+ @endforeach
- @endif - @foreach($ingredients as $k => $ingredient) -
-
-
- -
-
-
-
- -
-
- - @if($k == count($ingredients)-1) - - @endif -
- -
-
-
-
- @endforeach -
-
-
-
-
- Статус -
- + +
$state_row['article'] !== 'true', + ]) role="tabpanel" id="tabpanel-2" tabindex="0" + aria-labelledby="tab-2"> +
+
+
{{ __('recipe.record_state') }}
+ +
+
+
+ +
+
+
+
+ Статус +
+ +
+
-
-
-
{!! $description !!}
+
+ {!! $description !!}
@php $stepsCount = count($steps); @endphp - @for($i = 0; $i < $stepsCount; $i++) + @for ($i = 0; $i < $stepsCount; $i++)
{{ __('recipe.step') }} {{ $i + 1 }} @@ -230,8 +312,12 @@ @if (isset($steps[$i]['image']) && is_string($steps[$i]['image'])) @endif - - @error('steps.'. $i . '.image') {{ $message }} @enderror + + @error('steps.' . $i . '.image') + {{ $message }} + @enderror @if (!isset($steps[$i]['image']))
@@ -241,10 +327,15 @@ @endif - +
- - + +
@@ -259,20 +350,23 @@
{{ __('recipe.video_link') }}
- +
- - - + + +
-
- @foreach ($errors->all() as $message) -
{{ $message }}
- @endforeach -
+
+ @foreach ($errors->all() as $message) +
{{ $message }}
+ @endforeach +
- diff --git a/resources/views/livewire/recipe/like.blade.php b/resources/views/livewire/recipe/like.blade.php index d807ae0..f555a49 100644 --- a/resources/views/livewire/recipe/like.blade.php +++ b/resources/views/livewire/recipe/like.blade.php @@ -1,4 +1,4 @@ - diff --git a/resources/views/recipe/show.blade.php b/resources/views/recipe/show.blade.php index 2c25ff1..db42b65 100644 --- a/resources/views/recipe/show.blade.php +++ b/resources/views/recipe/show.blade.php @@ -1,147 +1,172 @@ @extends('layouts/eatvio') - @section('page_title', 'Recipe ' . $recipe->title) - @php - $recipeViewsCount = views($recipe)->unique()->count(); - @endphp - @section('main_section') -
-
-
- - Рецепты - -
-
- {{ $recipeViewsCount }} -
-
- @livewire('recipe.like-count', ['recipe' => $recipe]) -
-
- {{ $recipe->comments_count }} -
-
-
-
- {{ $author['name'] }} -
-
- @empty($author->profile_photo_path) - thumb - @else - thumb - @endempty -
-
-
-
-
-
-
-
-
-
- recipe -
-
-
-

- {{ $recipe->title }} -

- -
-
-
{{ __('recipe.t' . $recipe->cooking_time . "m") }}
-
{{ $recipe->steps->count() }} этапов
-
-

{!! $recipe->description !!}

- @if (strlen(trim($recipe->video_url)) > 4) - Посмотреть рецепт на YouTube - @endif -
-
-
-
-
- ПРОДУКТЫ: -
-
    - @foreach($recipe->ingredients as $ingredient) - @php - $localizedUnit = (isset($ingredient['unit']) && mb_strlen($ingredient['unit']) > 1) - ? $ingredient['unit'] - : 'gr'; - @endphp - @if(mb_strlen($ingredient['name']) > 1) -
  • {{ $ingredient['name'] }} - {{ $ingredient['portion'] }} {{ __('recipe.' . $localizedUnit ) }}
  • - @endif - @endforeach -
-
-
-
- ЦЕННОСТЬ: -
-
    -
  • WIP
  • - {{-- +@section('page_title', 'Recipe ' . $recipe->title) +@php + $recipeViewsCount = views($recipe) + ->unique() + ->count(); +@endphp +@section('main_section') +
    +
    +
    + + Рецепты + +
    +
    + {{ $recipeViewsCount }} +
    +
    + @livewire('recipe.like-count', ['recipe' => $recipe]) +
    +
    + {{ $recipe->comments_count }} +
    +
    +
    +
    + {{ $author['name'] }} +
    +
    + @empty($author->profile_photo_path) + thumb + @else + thumb + @endempty +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + recipe +
    +
    +
    +

    + {{ $recipe->title }} +

    + +
    + + +
      +
    • + Редактировать +
    • +
    • + +
    • +
    • + +
    • +
    • + +
    • + {{--
    • --}} + {{--
      ID: 2jkfk45JG
      --}} + {{--
    • --}} +
    + +
    + +
    +
    +
    {{ __('recipe.t' . $recipe->cooking_time . 'm') }}
    +
    {{ $recipe->steps->count() }} этапов
    +
    +

    {!! $recipe->description !!}

    + @if (strlen(trim($recipe->video_url)) > 4) + Посмотреть рецепт на YouTube + @endif +
    +
    +
    +
    +
    + ПРОДУКТЫ: +
    +
      + @foreach ($recipe->ingredients as $ingredient) + @php + $localizedUnit = isset($ingredient['unit']) && mb_strlen($ingredient['unit']) > 1 ? $ingredient['unit'] : 'gr'; + @endphp + @if (mb_strlen($ingredient['name']) > 1) +
    • {{ $ingredient['name'] }} - {{ $ingredient['portion'] }} + {{ __('recipe.' . $localizedUnit) }}
    • + @endif + @endforeach +
    +
    +
    +
    + ЦЕННОСТЬ: +
    +
      +
    • WIP
    • + {{--
    • Калории: 139.9 ккал
    • Белки: 20.4 гр
    • Жиры: 5.7 гр
    • Углеводы: 1.8 гр
    • --}} -
    -
    -
    -
    - ЦЕННОСТЬ: -
    -
    - @foreach($recipe->tags->unique() as $curTag) - {{ $curTag->name }} - @endforeach -
    -
    -
    - -
    -
    -
    -
    -
    -

    - ПОШАГОВЫЙ ФОТО РЕЦЕПТ - {{ $recipe->title }} -

    -
      - @foreach($recipe->steps as $step) +
+
+
+
+ ЦЕННОСТЬ: +
+
+ @foreach ($recipe->tags->unique() as $curTag) + {{ $curTag->name }} + @endforeach +
+
+
+ +
+
+
+
+
+

+ ПОШАГОВЫЙ ФОТО РЕЦЕПТ - {{ $recipe->title }} +

+
    + @foreach ($recipe->steps as $step) +
  1. +
    + @if (isset($step['image']) && is_string($step['image']) && strlen($step['image']) > 4) + step + @endif +
    +
    + + {!! $step['description'] !!} + +
    +
  2. + @endforeach -
  3. -
    - @if(isset($step['image']) && is_string($step['image']) && strlen($step["image"]) > 4) - step - @endif -
    -
    - - {!! $step['description'] !!} - -
    -
  4. - @endforeach - - {{--
  5. + {{--
  6. step
    @@ -162,115 +187,26 @@

--}} - -
- -
-
-

- Отзывы -

-
-
- - -
-
-
-
-
- user -
-
-
- Артём -
-
- После данного плана питания стал чувствовать себя куда лучше! Обязательно продолжу работать с Дмитрием! -
-
-
-
- Лёгкий -
-
- 5.0 -
-
-
-
-
- user -
-
-
- Артём -
-
- После данного плана питания стал чувствовать себя куда лучше! Обязательно продолжу работать с Дмитрием! -
-
-
-
- Лёгкий -
-
- 5.0 -
-
-
-
-
-
-
-
-
- user -
-
-
- Артём -
-
- Курить план – это плохо! Гласит лозунг и кричит Минздрав. Ну, конечно …Ничем не хуже водки, а водку везде продают и ничего.. ... Говорят, некоторые годами курят план и живут нормальной жизнью…Ну, если они считают это нормальной жизнью, то пусть и дальше существуют…Я не хочу…Я теперь спрашиваю себя – а зачем мне жить, что б просто курить траву?..Теперь мне плохо и траву курить, Проклятый мир! Даже год не покурил… Мне нужно что-то получше.. почище….ярче!!! -
-
-
-
- Лёгкий -
-
- 5.0 -
-
-
-
-
-
-
- -
-
- - - - - - - - - - -
- -
-
-
-
+ +
+ + +
+
+

+ ОТЗЫВЫ +

+ + @livewire('recipe.comment.show', ['recipe' => $recipe]) + @livewire('recipe.comment.create', ['recipe' => $recipe, 'user' => Auth::user()]) +
- @endsection - @push('jq_scripts') - - - @endpush +
+ + +@endsection +{{-- @push('jq_scripts') --}} +{{-- --}} +{{-- --}} +{{-- @endpush --}} diff --git a/tests/Feature/Recipe/CreateTest.php b/tests/Feature/Recipe/CreateTest.php index 5979aca..3bb77ce 100644 --- a/tests/Feature/Recipe/CreateTest.php +++ b/tests/Feature/Recipe/CreateTest.php @@ -196,3 +196,4 @@ final class CreateTest extends TestCase self::assertEquals($count, Recipe::count()); } } + diff --git a/tests/Feature/Recipe/EditFormTest.php b/tests/Feature/Recipe/EditFormTest.php deleted file mode 100644 index 67bbb9e..0000000 --- a/tests/Feature/Recipe/EditFormTest.php +++ /dev/null @@ -1,41 +0,0 @@ -refreshApplicationWithLocale('en'); - - $this->user = User::factory()->create(['is_consultant' => true]); - - $this->recipe = Recipe::inRandomOrder()->first(); - } - - public function test_edit_page_recipe_success(): void - { - $response = $this - ->actingAs($this->user) - ->get(route('recipe.edit', $this->recipe, false)); - - $response->assertSuccessful(); - } - -} diff --git a/tests/Feature/Recipe/EditTest.php b/tests/Feature/Recipe/EditTest.php new file mode 100644 index 0000000..ba5bb22 --- /dev/null +++ b/tests/Feature/Recipe/EditTest.php @@ -0,0 +1,192 @@ +refreshApplicationWithLocale('en'); + + $this->user = User::factory()->create(['is_consultant' => true]); + + $this->recipe = Recipe::inRandomOrder()->first(); + } + + public function test_edit_page_recipe_success(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('recipe.edit', $this->recipe, false)); + + $response->assertSuccessful(); + } + + public function testUpdateRecipePublishSuccess(): void + { + $this->actingAs($this->user); + + $recipe = $this->recipe = Recipe::factory()->make(); + + $recipeUpdate = Livewire::test(Edit::class, [ + 'recipe' => $this->recipe, + ]) + ->set('title', $recipe->title) + ->assertSet('title', $recipe->title) + ->set('image', $recipe->image) + ->set('state', $recipe->state) + ->assertSet('state', $recipe->state) + ->set('cooking_time', $recipe->cooking_time) + ->assertSet('cooking_time', $recipe->cooking_time) + ->set('ingredients', $recipe->ingredients) + ->assertSet('ingredients', $recipe->ingredients) + ->set('type', $recipe->type) + ->assertSet('type', $recipe->type) + ->set('description', $recipe->description) + ->assertSet('description', $recipe->description) + ->set('video_url', $recipe->video_url) + ->assertSet('video_url', $recipe->video_url) + ->call('publish') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); + + Storage::disk('public')->assertExists($this->recipe->image); + + // check data after update recipe + self::assertEquals($recipe->title, $recipeUpdate->title); + self::assertEquals($recipe->image, $recipeUpdate->image); + self::assertEquals($recipe->state, $recipeUpdate->state); + self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time); + self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients); + self::assertEquals($recipe->type, $recipeUpdate->type); + self::assertEquals($recipe->description, $recipeUpdate->description); + self::assertEquals($recipe->video_url, $recipeUpdate->video_url); + } + + + public function testUpdateRecipeDraftSuccess(): void + { + $this->actingAs($this->user); + + $recipe = $this->recipe = Recipe::factory()->make(); + + $recipeUpdate = Livewire::test(Edit::class, [ + 'recipe' => $this->recipe, + ]) + ->set('title', $recipe->title) + ->assertSet('title', $recipe->title) + ->set('image', $recipe->image) + ->set('state', $recipe->state) + ->assertSet('state', $recipe->state) + ->set('cooking_time', $recipe->cooking_time) + ->assertSet('cooking_time', $recipe->cooking_time) + ->set('ingredients', $recipe->ingredients) + ->assertSet('ingredients', $recipe->ingredients) + ->set('type', $recipe->type) + ->assertSet('type', $recipe->type) + ->set('description', $recipe->description) + ->assertSet('description', $recipe->description) + ->set('video_url', $recipe->video_url) + ->assertSet('video_url', $recipe->video_url) + ->call('draft') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); + + Storage::disk('public')->assertExists($this->recipe->image); + + // check data after update recipe + self::assertEquals($recipe->title, $recipeUpdate->title); + self::assertEquals($recipe->image, $recipeUpdate->image); + self::assertEquals('archived', $recipeUpdate->state); + self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time); + self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients); + self::assertEquals($recipe->type, $recipeUpdate->type); + self::assertEquals($recipe->description, $recipeUpdate->description); + self::assertEquals($recipe->video_url, $recipeUpdate->video_url); + } + + + public function testUpdateRecipePreviewSuccess(): void + { + $this->actingAs($this->user); + + $recipe = $this->recipe = Recipe::factory()->make(); + + $recipeUpdate = Livewire::test(Edit::class, [ + 'recipe' => $this->recipe, + ]) + ->set('title', $recipe->title) + ->assertSet('title', $recipe->title) + ->set('image', $recipe->image) + ->set('state', $recipe->state) + ->assertSet('state', $recipe->state) + ->set('cooking_time', $recipe->cooking_time) + ->assertSet('cooking_time', $recipe->cooking_time) + ->set('ingredients', $recipe->ingredients) + ->assertSet('ingredients', $recipe->ingredients) + ->set('type', $recipe->type) + ->assertSet('type', $recipe->type) + ->set('description', $recipe->description) + ->assertSet('description', $recipe->description) + ->set('video_url', $recipe->video_url) + ->assertSet('video_url', $recipe->video_url) + ->call('preview') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); + + Storage::disk('public')->assertExists($this->recipe->image); + + // check data after update recipe + self::assertEquals($recipe->title, $recipeUpdate->title); + self::assertEquals($recipe->image, $recipeUpdate->image); + self::assertEquals('archived', $recipeUpdate->state); + self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time); + self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients); + self::assertEquals($recipe->type, $recipeUpdate->type); + self::assertEquals($recipe->description, $recipeUpdate->description); + self::assertEquals($recipe->video_url, $recipeUpdate->video_url); + } + + + public function testNothingChange(): void + { + $this->actingAs($this->user); + + $recipeUpdate = Livewire::test(Edit::class, [ + 'recipe' => $this->recipe, + ]) + ->call('publish') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); + + Storage::disk('public')->assertExists($this->recipe->image); + + // check data after update recipe + self::assertEquals($this->recipe->title, $recipeUpdate->title); + self::assertEquals($this->recipe->image, $recipeUpdate->image); + self::assertEquals($this->recipe->state, $recipeUpdate->state); + self::assertEquals($this->recipe->cooking_time, $recipeUpdate->cooking_time); + self::assertEquals($this->recipe->ingredients, $recipeUpdate->ingredients); + self::assertEquals($this->recipe->type, $recipeUpdate->type); + self::assertEquals($this->recipe->description, $recipeUpdate->description); + self::assertEquals($this->recipe->video_url, $recipeUpdate->video_url); + } + +} diff --git a/tests/Feature/Recipe/IndexTest.php b/tests/Feature/Recipe/IndexTest.php index bc85a12..13557f0 100644 --- a/tests/Feature/Recipe/IndexTest.php +++ b/tests/Feature/Recipe/IndexTest.php @@ -33,3 +33,4 @@ class IndexTest extends TestCase ->assertOk(); } } + diff --git a/tests/Feature/Recipe/ShowTest.php b/tests/Feature/Recipe/ShowTest.php index a29cec0..cc71420 100644 --- a/tests/Feature/Recipe/ShowTest.php +++ b/tests/Feature/Recipe/ShowTest.php @@ -32,3 +32,4 @@ class ShowTest extends TestCase ->assertOk(); } } +