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/Livewire/Plan/Comment/Create.php b/app/Livewire/Plan/Comment/Create.php index 26b029b..cf89e2c 100644 --- a/app/Livewire/Plan/Comment/Create.php +++ b/app/Livewire/Plan/Comment/Create.php @@ -6,6 +6,7 @@ use Livewire\Component; use App\Models\Plan; use App\Models\PlanComment; use App\Models\User; +use Livewire\Attributes\Validate; class Create extends Component { @@ -21,6 +22,11 @@ class Create extends Component public function save() { + $this->validate([ + 'body' => 'required|min:10', + 'grade' => 'required', + ]); + $comment = new PlanComment(); $comment->grade = $this->grade; $comment->body = $this->body; diff --git a/app/Livewire/Plan/Comment/Show.php b/app/Livewire/Plan/Comment/Show.php index 3c54559..066fc25 100644 --- a/app/Livewire/Plan/Comment/Show.php +++ b/app/Livewire/Plan/Comment/Show.php @@ -8,6 +8,7 @@ use App\Models\Plan; class Show extends Component { public Plan $plan; + public array $tabpanelState = ['positive' => 'positive', 'negative' => false]; protected $listeners = ['commentAdded' => '$refresh']; @@ -15,4 +16,9 @@ class Show extends Component { return view('livewire.plan.comment.show'); } + + public function toggleTabpanelState($tabpanelName) + { + array_map(fn($key) => $key === $tabpanelName ? $this->tabpanelState[$tabpanelName] = $tabpanelName : $this->tabpanelState[$key] = false, array_keys($this->tabpanelState)); + } } 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/database/factories/PlanCommentFactory.php b/database/factories/PlanCommentFactory.php new file mode 100755 index 0000000..eb18786 --- /dev/null +++ b/database/factories/PlanCommentFactory.php @@ -0,0 +1,28 @@ + + */ +class PlanCommentFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + + return [ + 'grade' => $this->faker->randomDigit(), + 'body' => $this->faker->text(), + ]; + + } +} diff --git a/database/seeders/PlanCommentSeeder.php b/database/seeders/PlanCommentSeeder.php new file mode 100755 index 0000000..8f4c844 --- /dev/null +++ b/database/seeders/PlanCommentSeeder.php @@ -0,0 +1,38 @@ + 0 && Plan::count() > 0) { + $comments = PlanComment::factory()->count(5)->make(); + + $comments->each(function ($comment) { + $comment->author()->associate( + User::inRandomOrder() + ->first() + ->id + ); + + $comment->plan()->associate( + Plan::inRandomOrder() + ->first() + ->id + ); + + $comment->saveOrFail(); + }); + } + } +} diff --git a/resources/views/layouts/eatvio.blade.php b/resources/views/layouts/eatvio.blade.php index f70b4c4..309e77c 100644 --- a/resources/views/layouts/eatvio.blade.php +++ b/resources/views/layouts/eatvio.blade.php @@ -145,3 +145,4 @@ $isDiary = Str::of($curUrl)->test('/\/diary/'); + 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/livewire/plan/comment/create.blade.php b/resources/views/livewire/plan/comment/create.blade.php index 8873d7e..08bfe13 100644 --- a/resources/views/livewire/plan/comment/create.blade.php +++ b/resources/views/livewire/plan/comment/create.blade.php @@ -1,24 +1,18 @@ -
-
- - + diff --git a/resources/views/livewire/plan/comment/show.blade.php b/resources/views/livewire/plan/comment/show.blade.php index fd83b28..d952cbc 100644 --- a/resources/views/livewire/plan/comment/show.blade.php +++ b/resources/views/livewire/plan/comment/show.blade.php @@ -1,59 +1,89 @@
@php - $positivComments = $plan->comments()->where('grade', '>', '3'); - $negativeComments = $plan->comments()->where('grade', '<=', '3'); - $positiveCommmentsCount = $positivComments->count(); - $negativeCommentsCount = $negativeComments->count(); - @endphp - -
-
- @foreach($positivComments->get() as $comment) -
-
- -
- {{ $comment->author->name }} - {{ $comment->body }} + $positivComments = $plan->byPositive(); + $negativeComments = $plan->byNegative(); + + $positiveCommmentsCount = $positivComments->count(); + + $negativeCommentsCount = $negativeComments->count(); + + @endphp + +
+
+ + +
+ +
$tabpanelState['negative'] + ]) role="tabpanel" id="tabpanel-1" tabindex="0" aria-labelledby="tab-1"> + @foreach ($positivComments->get() as $comment) +
+
+
+ user
-
-
-
- - {{ $comment->grade }} +
+
+ {{ $comment->author->name }} +
+
+ {{ $comment->body }} +
+
+
+
+ {{ $plan->name }} +
+
+ {{ $comment->grade }} +
+ {{-- @livewire('plan.comment.upvote', ['comment' => $comment]) --}}
- @livewire('plan.comment.upvote', ['comment' => $comment])
@endforeach
-
- @foreach($negativeComments->get() as $comment) -
-
- -
- {{ $comment->author->name }} - {{ $comment->body }} + + +
$tabpanelState['positive'] + ]) role="tabpanel" id="tabpanel-1" tabindex="0" aria-labelledby="tab-1"> + @foreach ($negativeComments->get() as $comment) +
+
+
+ user
-
-
-
- - {{ $comment->grade }} +
+
+ {{ $comment->author->name }} +
+
+ {{ $comment->body }} +
+
+
+
+ {{ $plan->name }} +
+
+ {{ $comment->grade }} +
+ {{-- @livewire('plan.comment.upvote', ['comment' => $comment]) --}}
- @livewire('plan.comment.upvote', ['comment' => $comment])
@endforeach
+
+
diff --git a/resources/views/livewire/plan/create.blade.php b/resources/views/livewire/plan/create.blade.php index 6c1cad7..71daad3 100644 --- a/resources/views/livewire/plan/create.blade.php +++ b/resources/views/livewire/plan/create.blade.php @@ -373,8 +373,6 @@
- -
diff --git a/resources/views/plan/show.blade.php b/resources/views/plan/show.blade.php index ca3913f..d06a3dd 100644 --- a/resources/views/plan/show.blade.php +++ b/resources/views/plan/show.blade.php @@ -6,151 +6,121 @@ $authorPhoto = $plan->present()->getAuthorPhoto; $image = Storage::url($plan->image); - $planViewsCount = views($plan)->unique()->count(); + $planViewsCount = views($plan) + ->unique() + ->count(); @endphp @section('main_section') -
-
- Планы питания консультанта -
- -
-
-
-
-
{{ $plan->name }}
-
- {{ $planViewsCount }} - @livewire('plan.like-count', ['plan' => $plan]) - {{ $plan->comments_count }} -
-
- - - -
- - - - - - - - - -
Время прохождения плана:{{ $plan->duration }} дней
Проходят план:2 пользователя
- {{-- --}} -
- -
{!! $plan->details !!}
- -
- - - Комментировать - - - @livewire('plan.like', ['plan' => $plan]) - - - - Поделится - -
-
-
-
-
-
-
-
{{ $options1['price'] ?? '0' }} ₽
-
{{ $options1['short'] ?? ''}}
-
-
-
-
-

{{ $options1['description'] ?? '' }}

- @isset($options1['items']) -
    - @foreach($options1['items'] as $item) -
  • {{ $item }}
  • - @endforeach -
- @endisset - Заказать за {{ $options1['price'] ?? '0' }} ₽ -
-
-
- @if($plan->packets_count == 3) -
-
- -
-
-
-

{{ $options2['description'] ?? '' }}

- @isset($options2['items']) -
    - @foreach($options2['items'] as $item) -
  • {{ $item }}
  • - @endforeach -
- @endisset - Заказать за {{ $options2['price'] ?? '0' }} ₽ -
-
-
-
-
- -
-
-
-

{{ $options3['description'] ?? '' }}

- @isset($options3['items']) -
    - @foreach($options3['items'] as $item) -
  • {{ $item }}
  • - @endforeach -
- @endisset - Заказать за {{ $options3['price'] ?? '0' }} ₽ -
-
-
- @endif -
-
-
-
+ +
-
-
ОТЗЫВЫ
-
- @livewire('plan.comment.show', ['plan' => $plan]) - @livewire('plan.comment.create', ['plan' => $plan, 'user' => Auth::user()]) -
+
+
+
+
+
+ {{ $plan->name }} +
+
+
{{ $planViewsCount }}
+
@livewire('plan.like-count', ['plan' => $plan])
+
{{ $plan->comments_count }} +
+
+
+ + +
+ announcement +
+ + +
+
+
+
+ Время прохождения плана: +
+
+ {{ $plan->duration }} дней +
+
+
+
+ Проходят план: +
+
+ 2 пользователя +
+
+
+ +
+ +

+ {{ $plan->details }} +

+ + {{-- @livewire('plan.like', ['plan' => $plan]) --}} + + +
+
+ + @livewire('plan.accordion', ['plan' => $plan]) + +
+
+ + + +
+
+

+ ОТЗЫВЫ +

+ + @livewire('plan.comment.show', ['plan' => $plan]) + @livewire('plan.comment.create', ['plan' => $plan, 'user' => Auth::user()]) +
+ + +
+ @endsection @push('jq_scripts') - - + {{-- --}} + + @endpush