diff --git a/app/Http/Controllers/PlanController.php b/app/Http/Controllers/PlanController.php index 6484d94..0f76e56 100644 --- a/app/Http/Controllers/PlanController.php +++ b/app/Http/Controllers/PlanController.php @@ -24,9 +24,21 @@ class PlanController extends Controller } else { $plans = Plan::all(); } + + try{ + $this->checkArgumentsJson($plans); + }catch(\InvalidArgumentException $error){ + return back()->with('error', $error->getMessage()); + } + + return view('plan/index', ['plans' => $plans]); } + private function checkArgumentsJson($plans){ + + } + /** * Show the form for creating a new resource. * diff --git a/app/Livewire/Plan/Edit.php b/app/Livewire/Plan/Edit.php new file mode 100644 index 0000000..ff322e1 --- /dev/null +++ b/app/Livewire/Plan/Edit.php @@ -0,0 +1,190 @@ + false, 'slim' => false, 'behavior' => false, 'wellness' => false]; + public $details = ''; + public $packets_count = 1; + public $packet1_options = []; + public $packet2_options = []; + public $packet3_options = []; + public $packet1_options_input = []; + public $packet2_options_input = []; + public $packet3_options_input = []; + public $input_items_1 = ''; + public $input_items_2 = ''; + public $input_items_3 = ''; + public $isVisibleDuration = false; + public $isVisibleState = false; + + public function mount(Plan $plan) + { + $this->plan = $plan; + + $this->name = $plan->name; + $this->image = $plan->image; + $this->duration = $plan->duration; + $this->state = $plan->state; + $this->type = $plan->type; + $this->details = $plan->details; + $this->packets_count = $plan->packets_count; + + $this->packet1_options_input['short'] = $plan->packet1_options['short']; + $this->packet1_options_input['price'] = $plan->packet1_options['price']; + $this->packet1_options_input['description'] = $plan->packet1_options['description']; + // $this->input_items_1 = $plan->packet1_options['items']; + + $this->packet1_options['short'] = $plan->packet1_options['short']; + $this->packet1_options['price'] = $plan->packet1_options['price']; + $this->packet1_options['description'] = $plan->packet1_options['description']; + $this->packet1_options['items'] = $plan->packet1_options['items']; + + if ($plan->packets_count === 3) { + + $this->packet2_options_input['short'] = $plan->packet2_options['short']; + $this->packet2_options_input['price'] = $plan->packet2_options['price']; + $this->packet2_options_input['description'] = $plan->packet2_options['description']; + // $this->input_items_2 = $plan->packet1_options['items']; + + $this->packet2_options['short'] = $plan->packet2_options['short']; + $this->packet2_options['price'] = $plan->packet2_options['price']; + $this->packet2_options['description'] = $plan->packet2_options['description']; + $this->packet2_options['items'] = $plan->packet2_options['items']; + + $this->packet3_options_input['short'] = $plan->packet2_options['short']; + $this->packet3_options_input['price'] = $plan->packet2_options['price']; + $this->packet3_options_input['description'] = $plan->packet2_options['description']; + // $this->input_items_3 = $plan->packet1_options['items']; + + $this->packet3_options['short'] = $plan->packet2_options['short']; + $this->packet3_options['price'] = $plan->packet2_options['price']; + $this->packet3_options['description'] = $plan->packet2_options['description']; + $this->packet3_options['items'] = $plan->packet3_options['items']; + } + + // likes_count + // commentsCount + } + + protected function rules() + { + $rules = [ + 'name' => 'required|min:3', + // 'image' => 'image|max:2048', + 'duration' => 'required|numeric|min:7', + 'state' => 'required|in:draft,active,unactive', + 'type' => ['required', 'array:slim,fit,wellness,behavior', 'min:1'], + 'details' => 'required|min:3', + 'packets_count' => 'required|in:1,3', + 'packet1_options.short' => 'required|string|min:3', + 'packet1_options.price' => 'required|numeric|min:1', + 'packet1_options.description' => 'required|string|min:3', + 'packet1_options.items' => 'required|array|min:1', + ]; + + if ($this->packets_count === 3) { + $rules['packet2_options.short'] = 'required|string|min:3'; + $rules['packet2_options.price'] = 'required|numeric|min:1'; + $rules['packet2_options.description'] = 'required|string|min:3'; + $rules['packet2_options.items'] = 'required|array|min:1'; + $rules['packet3_options.short'] = 'required|string|min:3'; + $rules['packet3_options.price'] = 'required|numeric|min:1'; + $rules['packet3_options.description'] = 'required|string|min:3'; + $rules['packet3_options.items'] = 'required|array|min:1'; + } + + return $rules; + } + + public function showListDuration() + { + $this->isVisibleDuration = !$this->isVisibleDuration; + } + + public function showListState() + { + $this->isVisibleState = !$this->isVisibleState; + } + + public function toggleDuration($duration) + { + $this->duration = $duration; + $this->isVisibleDuration = false; + } + + public function toggleState($state) + { + $this->state = $state; + $this->isVisibleState = false; + } + + public function addPacketOption($options_type, $options_type_input) + { + $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_1; + $this->$options_type['items'][] = $this->input_items_2; + $this->$options_type['items'][] = $this->input_items_3; + + // delete empty value in items + $this->$options_type['items'] = array_filter($this->$options_type['items'], fn($item) => !empty($item)); + $this->reset('input_items_1'); + $this->reset('input_items_2'); + $this->reset('input_items_3'); + } + + public function publish() + { + $this->validate(); + + $this->plan->name = $this->name; + $this->plan->image = !is_string($this->image) ? $this->image->store('plans', 'public') : $this->image; + $this->plan->duration = $this->duration; + $this->plan->state = $this->state; + $this->plan->details = $this->details; + $this->plan->packets_count = $this->packets_count; + $this->plan->type = $this->type; + $this->plan->packet1_options = $this->packet1_options; + $this->plan->packet2_options = $this->packet2_options; + $this->plan->packet3_options = $this->packet3_options; + + $this->plan->update(); + + // $user = Auth::user(); + // $user->author_of_plans()->attach($plan->id); + + return redirect()->route('plan.show', $this->plan->id); + } + + public function addToDrafts() + { + $this->state = 'draft'; + $this->publish(); + } + + public function showPreview() + { + $this->state = 'unactive'; + $this->publish(); + } + + public function render() + { + return view('livewire.plan.edit'); + } +} diff --git a/resources/views/livewire/plan/edit.blade.php b/resources/views/livewire/plan/edit.blade.php new file mode 100644 index 0000000..5e49c6e --- /dev/null +++ b/resources/views/livewire/plan/edit.blade.php @@ -0,0 +1,493 @@ +
+
+
+ +

+ Мои планы +

+
+ +
+
+
+ Название +
+ +
+ +
+
+
+
+ Изображение +
+ +
+ +
+
+
+ Длительность плана питания +
+ +
+
+
+ + +
+
+
+ +
+
+
+ Статус +
+ +
+ +
+
+ + +
+
+
+ + +
+
+ +
+
+ Описание +
+ +
+
+ + +
+
+
+
+ + +
+
+
+ ОКАЗАНИЕ УСЛУГ +
+
+ + +
+
+ + @if ($packets_count === 1) +
+
+
+
+
+
+ Краткое описание +
+ +
+
+
+ Цена + + + 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 +
+
+ @endif + + +
+ + + +
+ +
+ +
+
diff --git a/resources/views/plan/edit_form.blade.php b/resources/views/plan/edit_form.blade.php index 7b95ef3..5cfe942 100644 --- a/resources/views/plan/edit_form.blade.php +++ b/resources/views/plan/edit_form.blade.php @@ -1,9 +1,13 @@ @extends('layouts/eatvio') - @section('main_section') - @livewire('plan.create') + @isset($plan) + @livewire('plan.edit', ['plan' => $plan]); + @else + @livewire('plan.create') + @endisset @endsection @push('css_head') {{-- --}} @endpush +