File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 22
33## Livewire Best Practices
44
5- ### Component Structure
5+ ### Component Structure using Laravel Volt
66``` php
77<?php
88
@@ -11,12 +11,15 @@ namespace App\Livewire;
1111use Livewire\Component;
1212use Livewire\WithPagination;
1313use Livewire\Attributes\Validate;
14+ use Livewire\Attributes\Url;
15+ use Livewire\Attributes\Computed;
1416
1517class CustomerList extends Component
1618{
1719 use WithPagination;
1820
1921 #[Validate('required|string|min:2')]
22+ #[Url]
2023 public string $search = '';
2124
2225 #[Validate('in:active,inactive,all')]
@@ -36,12 +39,11 @@ class CustomerList extends Component
3639
3740 public function render()
3841 {
39- return view('livewire.customer-list', [
40- 'customers' => $this->getCustomers(),
41- ]);
42+ return view('livewire.customer-list');
4243 }
4344
44- private function getCustomers()
45+ #[Computed]
46+ public function customers()
4547 {
4648 return Customer::query()
4749 ->when($this->search, fn($query) => $query->search($this->search))
You can’t perform that action at this time.
0 commit comments