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/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/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 @@
-
-
-
-
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
-
-
- Положительные{{ $positiveCommmentsCount }}
-
-
- Негативные{{ $negativeCommentsCount }}
-
-
-
-
- @foreach($positivComments->get() as $comment)
-
-
-
-
-
{{ $comment->author->name }}
-
{{ $comment->body }}
+ $positivComments = $recipe->positiveComments();
+ $negativeComments = $recipe->negativeComments();
+
+ $positiveCommmentsCount = $positivComments->count();
+
+ $negativeCommentsCount = $negativeComments->count();
+
+ @endphp
+
+
+
+ Положительные {{ $positiveCommmentsCount }}
+ Негативные {{ $negativeCommentsCount }}
+
+
+
$tabpanelState['negative']
+ ]) role="tabpanel" id="tabpanel-1" tabindex="0" aria-labelledby="tab-1">
+ @foreach ($positivComments->get() as $comment)
+
+
+
+
-
-
-
-
-
{{ $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)
+
+
+
+
-
-
-
-
-
{{ $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 }}>
$isDownVoted])>
$isDownVoted])>
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 @@