refactor: Add return type hints to Livewire methods

This commit is contained in:
Yoga Pangestu 2025-12-19 21:31:57 +07:00
parent de6b1aced4
commit 5cd4a98b09
7 changed files with 28 additions and 20 deletions

View File

@ -2,6 +2,7 @@
namespace App\Livewire\Home\Article;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Layout;
use Livewire\Component;
@ -14,7 +15,7 @@ class Index extends Component
public ?string $slug = null;
public function mount(?string $slug = null)
public function mount(?string $slug = null): void
{
if ($slug) {
$this->isDetail = true;
@ -22,7 +23,7 @@ public function mount(?string $slug = null)
}
}
public function render()
public function render(): View
{
return view(
$this->isDetail

View File

@ -2,6 +2,7 @@
namespace App\Livewire\Home\Cart;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Layout;
use Livewire\Component;
@ -10,7 +11,7 @@
])]
class Index extends Component
{
public function render()
public function render(): View
{
return view('livewire.home.cart.index');
}

View File

@ -2,6 +2,7 @@
namespace App\Livewire\Home\Faq;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Layout;
use Livewire\Component;
@ -10,7 +11,7 @@
])]
class Index extends Component
{
public function render()
public function render(): View
{
return view('livewire.home.faq.index');
}

View File

@ -7,6 +7,8 @@
use App\Models\Customer;
use App\Models\Faq;
use App\Models\PerfumeFeature;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Storage;
use Livewire\Attributes\Layout;
use Livewire\Component;
@ -28,11 +30,11 @@ class Index extends Component
public $latestMembers = [];
public function mount()
public function mount(): void
{
$this->brands = Brand::orderBy('sort_order')
->get()
->map(fn(Brand $brand) => [
->map(fn (Brand $brand) => [
'name' => $brand->name,
'image' => $brand->getFirstMediaUrl('image') ? Storage::url($brand->getFirstMediaUrl('image')) : asset('assets/images/logo.png'),
])
@ -40,7 +42,7 @@ public function mount()
$this->perfumeFeatures = PerfumeFeature::orderBy('sort_order')
->get()
->map(fn(PerfumeFeature $perfumeFeature) => [
->map(fn (PerfumeFeature $perfumeFeature) => [
'name' => $perfumeFeature->name,
'description' => $perfumeFeature->description,
])
@ -48,7 +50,7 @@ public function mount()
$this->faqs = Faq::orderBy('sort_order')
->get()
->map(fn(Faq $faq) => [
->map(fn (Faq $faq) => [
'question' => $faq->question,
'answer' => $faq->answer,
])
@ -56,7 +58,7 @@ public function mount()
$this->whyChooseUs = ChooseUs::orderBy('sort_order')
->get()
->map(fn(ChooseUs $chooseUs) => [
->map(fn (ChooseUs $chooseUs) => [
'name' => $chooseUs->name,
'description' => $chooseUs->description,
])
@ -70,19 +72,19 @@ public function mount()
->get();
}
public function render()
public function render(): View
{
return view('livewire.home.index', [
'pageTitle' => 'Beranda',
]);
}
public function goToProduct()
public function goToProduct(): RedirectResponse
{
return redirect('/product');
}
public function goToVoucher()
public function goToVoucher(): RedirectResponse
{
return redirect('/voucher');
}

View File

@ -2,6 +2,7 @@
namespace App\Livewire\Home;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Layout;
use Livewire\Component;
@ -10,7 +11,7 @@
])]
class Outlet extends Component
{
public function render()
public function render(): View
{
return view('livewire.home.outlets');
}

View File

@ -2,6 +2,7 @@
namespace App\Livewire\Home\Product;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Layout;
use Livewire\Component;
@ -14,7 +15,7 @@ class Index extends Component
public ?string $slug = null;
public function mount(?string $slug = null)
public function mount(?string $slug = null): void
{
if ($slug) {
$this->isDetail = true;
@ -22,7 +23,7 @@ public function mount(?string $slug = null)
}
}
public function render()
public function render(): View
{
return view(
$this->isDetail

View File

@ -4,6 +4,7 @@
use App\Models\Outlet;
use App\Models\Voucher as VoucherModel;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Layout;
use Livewire\Component;
use Livewire\WithPagination;
@ -23,27 +24,27 @@ class Voucher extends Component
public ?string $sort = null;
public function mount()
public function mount(): void
{
$this->outlets = Outlet::query()->operational()->pluck('name', 'id');
}
public function updatedSearch()
public function updatedSearch(): void
{
$this->resetPage();
}
public function updatedOutletId()
public function updatedOutletId(): void
{
$this->resetPage();
}
public function updatedSort()
public function updatedSort(): void
{
$this->resetPage();
}
public function render()
public function render(): View
{
$vouchers = VoucherModel::where(function ($query) {
$query->where('name', 'like', '%'.$this->search.'%')