From 6bf87ef34f6a4c716c6babb8e8abe13c6533f4a2 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Sun, 24 Dec 2023 20:33:53 +0300 Subject: [PATCH] added create recipe page --- app/Livewire/Recipe/Create.php | 62 +-- .../views/livewire/recipe/create.blade.php | 393 +++++++++++------- 2 files changed, 268 insertions(+), 187 deletions(-) diff --git a/app/Livewire/Recipe/Create.php b/app/Livewire/Recipe/Create.php index 65cf6a3..1713ae1 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,20 @@ 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 +150,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 +159,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 +166,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 +176,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/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
-