forked from eatvio/eatvio-infra
added accordion toggle to show plan
This commit is contained in:
@@ -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,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
40
app/Livewire/Plan/Accordion.php
Normal file
40
app/Livewire/Plan/Accordion.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Plan;
|
||||
|
||||
use App\Models\Plan;
|
||||
use Livewire\Component;
|
||||
|
||||
class Accordion extends Component
|
||||
{
|
||||
public Plan $plan;
|
||||
public $accordionState = ['options1' => 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));
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
use Laracasts\Presenter\PresentableTrait;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\PlanLike;
|
||||
use App\Presenters\PlanPresenter;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use CyrildeWit\EloquentViewable\InteractsWithViews;
|
||||
use CyrildeWit\EloquentViewable\Contracts\Viewable;
|
||||
use CyrildeWit\EloquentViewable\InteractsWithViews;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Laracasts\Presenter\PresentableTrait;
|
||||
|
||||
class Plan extends Model implements Viewable
|
||||
{
|
||||
@@ -18,7 +19,6 @@ class Plan extends Model implements Viewable
|
||||
use InteractsWithViews;
|
||||
use PresentableTrait;
|
||||
|
||||
|
||||
protected $withCount = [
|
||||
'likes',
|
||||
'comments'
|
||||
@@ -31,10 +31,8 @@ class Plan extends Model implements Viewable
|
||||
'packet3_options' => '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');
|
||||
}
|
||||
}
|
||||
|
||||
99
resources/views/livewire/plan/accordion.blade.php
Normal file
99
resources/views/livewire/plan/accordion.blade.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<div class="settings__price" data-spollers data-one-spoller>
|
||||
<div class="settings__price-item">
|
||||
<button type="button" @class([
|
||||
'settings__price-btn',
|
||||
'_active' => $accordionState['options1'],
|
||||
]) wire:click='toggleAccordionState("options1","options2", "options3")' data-spoller>
|
||||
<strong>
|
||||
{{ $options1['price'] ?? '0' }} ₽
|
||||
</strong>
|
||||
{{ $options1['short'] ?? '' }}
|
||||
</button>
|
||||
<div class="settings__price-body" @style(['display: none' => !$accordionState['options1'], 'display: block' => $accordionState['options1']])>
|
||||
<div class="settings__price-desc">
|
||||
{{ $options1['description'] ?? '' }}
|
||||
</div>
|
||||
|
||||
@isset($options1['items'])
|
||||
@foreach ($options1['items'] as $item)
|
||||
<ul class="settings__price-list">
|
||||
<li>
|
||||
{{ $item }}
|
||||
<span class="settings__price-icon icon-check-square"></span>
|
||||
{{-- <span class="settings__price-icon">-</span> --}}
|
||||
</li>
|
||||
</ul>
|
||||
@endforeach
|
||||
@endisset
|
||||
<button type="button" class="settings__price-bid btn btn-green">Заказать за
|
||||
{{ $options1['price'] ?? '0' }}₽</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if ($plan->packets_count == 3)
|
||||
<div class="settings__price-item">
|
||||
<button type="button" @class([
|
||||
'settings__price-btn',
|
||||
'_active' => $accordionState['options2'],
|
||||
]) wire:click='toggleAccordionState("options2")' data-spoller>
|
||||
<strong>
|
||||
{{ $options2['price'] ?? '0' }} ₽
|
||||
</strong>
|
||||
{{ $options2['short'] ?? '' }}
|
||||
</button>
|
||||
<div class="settings__price-body" @style(['display: none' => !$accordionState['options2'], 'display: block' => $accordionState['options2']])>
|
||||
<div class="settings__price-desc">
|
||||
{{ $options2['description'] ?? '' }}
|
||||
</div>
|
||||
|
||||
@isset($options2['items'])
|
||||
@foreach ($options2['items'] as $item)
|
||||
<ul class="settings__price-list">
|
||||
<li>
|
||||
{{ $item }}
|
||||
<span class="settings__price-icon icon-check-square"></span>
|
||||
{{-- <span class="settings__price-icon">-</span> --}}
|
||||
</li>
|
||||
</ul>
|
||||
@endforeach
|
||||
@endisset
|
||||
<button type="button" class="settings__price-bid btn btn-green">Заказать за
|
||||
{{ $options2['price'] ?? '0' }}
|
||||
₽</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings__price-item">
|
||||
<button type="button" @class([
|
||||
'settings__price-btn',
|
||||
'_active' => $accordionState['options3'],
|
||||
]) wire:click='toggleAccordionState("options3")'
|
||||
data-spoller>
|
||||
<strong>
|
||||
{{ $options3['price'] ?? '0' }} ₽
|
||||
</strong>
|
||||
{{ $options3['short'] ?? '' }}
|
||||
</button>
|
||||
<div class="settings__price-body" @style(['display: none' => !$accordionState['options3'], 'display: block' => $accordionState['options3']])>
|
||||
<div class="settings__price-desc">
|
||||
{{ $options3['description'] ?? '' }}
|
||||
</div>
|
||||
|
||||
@isset($options3['items'])
|
||||
@foreach ($options3['items'] as $item)
|
||||
<ul class="settings__price-list">
|
||||
<li>
|
||||
{{ $item }}
|
||||
<span class="settings__price-icon icon-check-square"></span>
|
||||
{{-- <span class="settings__price-icon">-</span> --}}
|
||||
</li>
|
||||
</ul>
|
||||
@endforeach
|
||||
@endisset
|
||||
<button type="button" class="settings__price-bid btn btn-green">Заказать за
|
||||
{{ $options3['price'] ?? '0' }}
|
||||
₽</button>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@@ -97,97 +97,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@livewire('plan.accordion', ['plan' => $plan])
|
||||
|
||||
<div class="settings__price" data-spollers data-one-spoller>
|
||||
<div class="settings__price-item">
|
||||
<button class="settings__price-btn _active" data-spoller>
|
||||
<strong>
|
||||
{{ $options1['price'] ?? '0' }} ₽
|
||||
</strong>
|
||||
{{ $options1['short'] ?? '' }}
|
||||
</button>
|
||||
<div class="settings__price-body">
|
||||
<div class="settings__price-desc">
|
||||
{{ $options1['description'] ?? '' }}
|
||||
</div>
|
||||
|
||||
@isset($options1['items'])
|
||||
@foreach ($options1['items'] as $item)
|
||||
<ul class="settings__price-list">
|
||||
<li>
|
||||
{{ $item }}
|
||||
<span class="settings__price-icon icon-check-square"></span>
|
||||
{{-- <span class="settings__price-icon">-</span> --}}
|
||||
</li>
|
||||
</ul>
|
||||
@endforeach
|
||||
@endisset
|
||||
<button type="button" class="settings__price-bid btn btn-green">Заказать за
|
||||
{{ $options1['price'] ?? '0' }}
|
||||
₽</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if ($plan->packets_count == 3)
|
||||
<div class="settings__price-item">
|
||||
<button class="settings__price-btn _active" data-spoller>
|
||||
<strong>
|
||||
{{ $options2['price'] ?? '0' }} ₽
|
||||
</strong>
|
||||
{{ $options2['short'] ?? '' }}
|
||||
</button>
|
||||
<div class="settings__price-body">
|
||||
<div class="settings__price-desc">
|
||||
{{ $options2['description'] ?? '' }}
|
||||
</div>
|
||||
|
||||
@isset($options2['items'])
|
||||
@foreach ($options2['items'] as $item)
|
||||
<ul class="settings__price-list">
|
||||
<li>
|
||||
{{ $item }}
|
||||
<span class="settings__price-icon icon-check-square"></span>
|
||||
{{-- <span class="settings__price-icon">-</span> --}}
|
||||
</li>
|
||||
</ul>
|
||||
@endforeach
|
||||
@endisset
|
||||
<button type="button" class="settings__price-bid btn btn-green">Заказать за
|
||||
{{ $options2['price'] ?? '0' }}
|
||||
₽</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings__price-item">
|
||||
<button class="settings__price-btn _active" data-spoller>
|
||||
<strong>
|
||||
{{ $options3['price'] ?? '0' }} ₽
|
||||
</strong>
|
||||
{{ $options3['short'] ?? '' }}
|
||||
</button>
|
||||
<div class="settings__price-body">
|
||||
<div class="settings__price-desc">
|
||||
{{ $options3['description'] ?? '' }}
|
||||
</div>
|
||||
|
||||
@isset($options3['items'])
|
||||
@foreach ($options3['items'] as $item)
|
||||
<ul class="settings__price-list">
|
||||
<li>
|
||||
{{ $item }}
|
||||
<span class="settings__price-icon icon-check-square"></span>
|
||||
{{-- <span class="settings__price-icon">-</span> --}}
|
||||
</li>
|
||||
</ul>
|
||||
@endforeach
|
||||
@endisset
|
||||
<button type="button" class="settings__price-bid btn btn-green">Заказать за
|
||||
{{ $options3['price'] ?? '0' }}
|
||||
₽</button>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -198,122 +109,18 @@
|
||||
<h2 class="reviews__title title">
|
||||
ОТЗЫВЫ
|
||||
</h2>
|
||||
<div class="reviews__tabs tabs">
|
||||
<div class="tablist" role="tablist" aria-labelledby="label">
|
||||
<button class="tab" role="tab" type="button" id="tab-1" aria-selected="true"
|
||||
aria-controls="tabpanel-1">Положительные 2</button>
|
||||
<button class="tab" role="tab" type="button" id="tab-2" aria-selected="false"
|
||||
aria-controls="tabpanel-2" tabindex="-1">Негативные 1</button>
|
||||
</div>
|
||||
<div class="tabpanel" role="tabpanel" id="tabpanel-1" tabindex="0" aria-labelledby="tab-1">
|
||||
<div class="reviews__items">
|
||||
<div class="review">
|
||||
<div class="review__thumb">
|
||||
<img src="img/user.png" class="cover-image" alt="user">
|
||||
</div>
|
||||
<div class="review__content">
|
||||
<div class="review__name">
|
||||
Артём
|
||||
</div>
|
||||
<blockquote class="review__quote">
|
||||
После данного плана питания стал чувствовать себя куда лучше! Обязательно продолжу
|
||||
работать с Дмитрием!
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="review__info">
|
||||
<div class="review__programm">
|
||||
Лёгкий
|
||||
</div>
|
||||
<div class="review__rate icon-star">
|
||||
5.0
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="review">
|
||||
<div class="review__thumb">
|
||||
<img src="img/user.png" class="cover-image" alt="user">
|
||||
</div>
|
||||
<div class="review__content">
|
||||
<div class="review__name">
|
||||
Артём
|
||||
</div>
|
||||
<blockquote class="review__quote">
|
||||
После данного плана питания стал чувствовать себя куда лучше! Обязательно продолжу
|
||||
работать с Дмитрием!
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="review__info">
|
||||
<div class="review__programm">
|
||||
Лёгкий
|
||||
</div>
|
||||
<div class="review__rate icon-star">
|
||||
5.0
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tabpanel" role="tabpanel" id="tabpanel-2" tabindex="0" aria-labelledby="tab-2">
|
||||
<div class="reviews__items">
|
||||
<div class="review">
|
||||
<div class="review__thumb">
|
||||
<img src="img/user.png" class="cover-image" alt="user">
|
||||
</div>
|
||||
<div class="review__content">
|
||||
<div class="review__name">
|
||||
Артём
|
||||
</div>
|
||||
<blockquote class="review__quote">
|
||||
Курить план – это плохо! Гласит лозунг и кричит Минздрав. Ну, конечно …Ничем не хуже
|
||||
водки, а водку везде продают и ничего.. ... Говорят, некоторые годами курят план и
|
||||
живут нормальной жизнью…Ну, если они считают это нормальной жизнью, то пусть и
|
||||
дальше существуют…Я не хочу…Я теперь спрашиваю себя – а зачем мне жить, что б просто
|
||||
курить траву?..Теперь мне плохо и траву курить, Проклятый мир! Даже год не покурил…
|
||||
Мне нужно что-то получше.. почище….ярче!!!
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="review__info">
|
||||
<div class="review__programm">
|
||||
Лёгкий
|
||||
</div>
|
||||
<div class="review__rate icon-star">
|
||||
5.0
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form action="" class="reviews__form">
|
||||
<textarea class="textarea textarea-white" placeholder="Введите отзыв"></textarea>
|
||||
<div class="reviews__form-column">
|
||||
<div class="reviews__form-rate star-rating">
|
||||
<input type="radio" name="rate" id="rate-5" value="5"
|
||||
class="star-rating__input hidden" hidden>
|
||||
<label class="star-rating__label" for="rate-5"></label>
|
||||
<input type="radio" name="rate" id="rate-4" value="4"
|
||||
class="star-rating__input hidden" hidden>
|
||||
<label class="star-rating__label" for="rate-4"></label>
|
||||
<input type="radio" name="rate" id="rate-3" value="3"
|
||||
class="star-rating__input hidden" hidden>
|
||||
<label class="star-rating__label" for="rate-3"></label>
|
||||
<input type="radio" name="rate" id="rate-2" value="2"
|
||||
class="star-rating__input hidden" hidden>
|
||||
<label class="star-rating__label" for="rate-2"></label>
|
||||
<input type="radio" name="rate" id="rate-1" value="1"
|
||||
class="star-rating__input hidden" hidden>
|
||||
<label class="star-rating__label" for="rate-1"></label>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary">Оставть отзыв</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@livewire('plan.comment.show', ['plan' => $plan])
|
||||
@livewire('plan.comment.create', ['plan' => $plan, 'user' => Auth::user()])
|
||||
</div>
|
||||
|
||||
|
||||
</section>
|
||||
</section>
|
||||
@endsection
|
||||
|
||||
|
||||
@endsection
|
||||
|
||||
@push('jq_scripts')
|
||||
<script src="/js/bootstrap.min.js"></script>
|
||||
<script src="/js/bootstrap.bundle.min.js"></script>
|
||||
@endpush
|
||||
@push('jq_scripts')
|
||||
{{-- <script src="js/app.min.js"></script> --}}
|
||||
<script src="/js/bootstrap.min.js"></script>
|
||||
<script src="/js/bootstrap.bundle.min.js"></script>
|
||||
@endpush
|
||||
|
||||
Reference in New Issue
Block a user