55use App\Livewire\Actions\ Logout ;
66use App\Models\ Category ;
77use App\Services\ SettingService ;
8- use Illuminate\Database\Eloquent\ Collection ;
98use Illuminate\Support\Facades\ Cache ;
109use Livewire\ Component ;
1110
1211new class extends Component
1312{
14- public Collection $categories ;
13+ public array $categories ;
1514
1615 public bool $showRegisterButton ;
1716
1817 public function mount (): void
1918 {
2019 $this -> categories = Cache:: remember (' categories' , now ()-> addDay (), function () {
21- return Category:: all ([' id' , ' name' , ' icon' ]);
20+ return Category:: all ([' id' , ' name' , ' icon' ])-> map (fn (Category $category ) => [
21+ ' id' => $category -> id ,
22+ ' name' => $category -> name ,
23+ ' icon' => $category -> icon ,
24+ ' link_with_name' => $category -> link_with_name ,
25+ ])-> toArray ();
2226 });
2327
2428 $this -> showRegisterButton = SettingService:: isRegisterAllowed ();
@@ -98,12 +102,12 @@ class="hidden dark:block size-8"
98102
99103 @foreach ($categories as $category )
100104 <x-skew-underline-link
101- :link =" $category-> link_with_name"
102- :selected =" urldecode(request()->url()) === urldecode($category-> link_with_name)"
103- :icon =" $category-> icon"
104- wire:key =" category-{{ $category -> id } }"
105+ :link =" $category[' link_with_name'] "
106+ :selected =" urldecode(request()->url()) === urldecode($category[' link_with_name'] )"
107+ :icon =" $category[' icon'] "
108+ wire:key =" category-{{ $category [ ' id ' ] } }"
105109 >
106- {{ $category -> name } }
110+ {{ $category [ ' name' ] } }
107111 </x-skew-underline-link >
108112 @endforeach
109113 </nav >
@@ -414,10 +418,10 @@ class="px-2 pt-2 pb-3 space-y-1 lg:hidden"
414418
415419 @foreach ($categories as $category )
416420 @php
417- $inCategoryPage = urldecode (request ()-> url ()) === urldecode ($category -> link_with_name );
421+ $inCategoryPage = urldecode (request ()-> url ()) === urldecode ($category [ ' link_with_name' ] );
418422 @endphp
419423 <a
420- href =" {{ $category -> link_with_name } }"
424+ href =" {{ $category [ ' link_with_name' ] } }"
421425 @if ($inCategoryPage ) aria-current =" page" @endif
422426 @class ([
423427 ' block px-3 py-2 rounded-md font-medium flex items-center' ,
@@ -426,8 +430,8 @@ class="px-2 pt-2 pb-3 space-y-1 lg:hidden"
426430 ] )
427431 wire:navigate
428432 >
429- <div class =" w-4" >{!! $category -> icon ! !} </div >
430- <span class =" ml-2" >{{ $category -> name } } </span >
433+ <div class =" w-4" >{!! $category [ ' icon' ] ! !} </div >
434+ <span class =" ml-2" >{{ $category [ ' name' ] } } </span >
431435 </a >
432436 @endforeach
433437 </nav >
0 commit comments