diff --git a/app/Http/Controllers/PlanController.php b/app/Http/Controllers/PlanController.php index 474a66f..6484d94 100644 --- a/app/Http/Controllers/PlanController.php +++ b/app/Http/Controllers/PlanController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Models\Plan; use App\Models\User; use Illuminate\Http\Request; +use App\Models\PlanComment; class PlanController extends Controller { @@ -65,16 +66,16 @@ class PlanController extends Controller // $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; + // $options1 = $plan->packet1_options; + // $options2 = $plan->packet2_options; + // $options3 = $plan->packet2_options; return view('plan/show', [ 'plan' => $plan, - 'options1' => $options1, - 'options2' => $options2, - 'options3' => $options3 + // 'options1' => $options1, + // 'options2' => $options2, + // 'options3' => $options3, ] ); } diff --git a/app/Livewire/Plan/Accordion.php b/app/Livewire/Plan/Accordion.php new file mode 100644 index 0000000..06dad1b --- /dev/null +++ b/app/Livewire/Plan/Accordion.php @@ -0,0 +1,40 @@ + false, 'options2' => false, 'options3' => false]; + public $options1; + public $options2; + public $options3; + + public function mount(Plan $plan): void + { + $this->plan = $plan; + $this->options1 = $plan->packet1_options; + $this->options2 = $plan->packet2_options; + $this->options3 = $plan->packet3_options; + + } + + public function render() + { + return view('livewire.plan.accordion'); + } + + public function toggleAccordionState($optionName) + { + $this->accordionState[$optionName] = !$this->accordionState[$optionName]; + + + // 1. Если у нас 1 true все остальные делать false(чтобы закрывать остальные вкладки у которых не true) + // a. у нас есть ключ у которого будет true + // b. проходим по всем ключам accordionState и все кроме true делаем false + array_map(fn($key) => $key === $optionName ?: $this->accordionState[$key] = false, array_keys($this->accordionState)); + } +} diff --git a/app/Models/Plan.php b/app/Models/Plan.php index 20a25d3..7e168c9 100644 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -1,16 +1,17 @@ 'array', ]; - protected $presenter = PlanPresenter::class; - public function author() { return $this->belongsToMany(User::class, 'plan_author', 'plan_id', 'user_id'); @@ -63,12 +61,12 @@ class Plan extends Model implements Viewable { $result = []; for ($i = 1; $i <= $this->packets_count; $i++) { - $key = "packet" . $i . "_options"; + $key = 'packet' . $i . '_options'; // $data = $this->unserializeOptionsObj($this->$key); $data = $this->$key; if (!is_null($data)) { - $result = array_merge($result, data_get($data, "items", [])); + $result = array_merge($result, data_get($data, 'items', [])); } } @@ -81,7 +79,7 @@ class Plan extends Model implements Viewable $data = $this->type; return new Attribute( - get: fn () => array_keys($data), + get: fn() => array_keys($data), ); } @@ -89,18 +87,18 @@ class Plan extends Model implements Viewable { $result = 0; for ($i = 1; $i <= $this->packets_count; $i++) { - $key = "packet" . $i . "_options"; + $key = 'packet' . $i . '_options'; // 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 ; + $curPrice = (int) data_get($data, 'price', 0); + $result = $curPrice > $result ? $curPrice : $result; } } return new Attribute( - get: fn () => $result, + get: fn() => $result, ); } @@ -128,4 +126,14 @@ class Plan extends Model implements Viewable } return json_decode(stripslashes($str), true); } + + public function scopeByNegative(Builder $query) + { + return static::comments()->where('grade', '<=', '3'); + } + + public function scopeByPositive(Builder $query) + { + return static::comments()->where('grade', '>', '3'); + } } diff --git a/resources/views/livewire/plan/accordion.blade.php b/resources/views/livewire/plan/accordion.blade.php new file mode 100644 index 0000000..2626ac2 --- /dev/null +++ b/resources/views/livewire/plan/accordion.blade.php @@ -0,0 +1,99 @@ +
+
+ +
!$accordionState['options1'], 'display: block' => $accordionState['options1']])> +
+ {{ $options1['description'] ?? '' }} +
+ + @isset($options1['items']) + @foreach ($options1['items'] as $item) +
    +
  • + {{ $item }} + + {{-- - --}} +
  • +
+ @endforeach + @endisset + +
+
+ + @if ($plan->packets_count == 3) +
+ +
!$accordionState['options2'], 'display: block' => $accordionState['options2']])> +
+ {{ $options2['description'] ?? '' }} +
+ + @isset($options2['items']) + @foreach ($options2['items'] as $item) +
    +
  • + {{ $item }} + + {{-- - --}} +
  • +
+ @endforeach + @endisset + +
+
+ +
+ +
!$accordionState['options3'], 'display: block' => $accordionState['options3']])> +
+ {{ $options3['description'] ?? '' }} +
+ + @isset($options3['items']) + @foreach ($options3['items'] as $item) +
    +
  • + {{ $item }} + + {{-- - --}} +
  • +
+ @endforeach + @endisset + +
+
+ @endif +
diff --git a/resources/views/plan/show.blade.php b/resources/views/plan/show.blade.php index 90fc933..d06a3dd 100644 --- a/resources/views/plan/show.blade.php +++ b/resources/views/plan/show.blade.php @@ -97,97 +97,8 @@ + @livewire('plan.accordion', ['plan' => $plan]) -
-
- -
-
- {{ $options1['description'] ?? '' }} -
- - @isset($options1['items']) - @foreach ($options1['items'] as $item) -
    -
  • - {{ $item }} - - {{-- - --}} -
  • -
- @endforeach - @endisset - -
-
- - @if ($plan->packets_count == 3) -
- -
-
- {{ $options2['description'] ?? '' }} -
- - @isset($options2['items']) - @foreach ($options2['items'] as $item) -
    -
  • - {{ $item }} - - {{-- - --}} -
  • -
- @endforeach - @endisset - -
-
- -
- -
-
- {{ $options3['description'] ?? '' }} -
- - @isset($options3['items']) - @foreach ($options3['items'] as $item) -
    -
  • - {{ $item }} - - {{-- - --}} -
  • -
- @endforeach - @endisset - -
-
- @endif -
@@ -198,122 +109,18 @@

ОТЗЫВЫ

-
-
- - -
-
-
-
-
- user -
-
-
- Артём -
-
- После данного плана питания стал чувствовать себя куда лучше! Обязательно продолжу - работать с Дмитрием! -
-
-
-
- Лёгкий -
-
- 5.0 -
-
-
-
-
- user -
-
-
- Артём -
-
- После данного плана питания стал чувствовать себя куда лучше! Обязательно продолжу - работать с Дмитрием! -
-
-
-
- Лёгкий -
-
- 5.0 -
-
-
-
-
-
-
-
-
- user -
-
-
- Артём -
-
- Курить план – это плохо! Гласит лозунг и кричит Минздрав. Ну, конечно …Ничем не хуже - водки, а водку везде продают и ничего.. ... Говорят, некоторые годами курят план и - живут нормальной жизнью…Ну, если они считают это нормальной жизнью, то пусть и - дальше существуют…Я не хочу…Я теперь спрашиваю себя – а зачем мне жить, что б просто - курить траву?..Теперь мне плохо и траву курить, Проклятый мир! Даже год не покурил… - Мне нужно что-то получше.. почище….ярче!!! -
-
-
-
- Лёгкий -
-
- 5.0 -
-
-
-
-
-
-
- -
-
- - - - - - - - - - -
- -
-
+ + @livewire('plan.comment.show', ['plan' => $plan]) + @livewire('plan.comment.create', ['plan' => $plan, 'user' => Auth::user()]) + + + +@endsection - - @endsection - - @push('jq_scripts') - - - @endpush +@push('jq_scripts') + {{-- --}} + + +@endpush