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 2
2
3
3
## Livewire Best Practices
4
4
5
- ### Component Structure
5
+ ### Component Structure using Laravel Volt
6
6
``` php
7
7
<?php
8
8
@@ -11,12 +11,15 @@ namespace App\Livewire;
11
11
use Livewire\Component;
12
12
use Livewire\WithPagination;
13
13
use Livewire\Attributes\Validate;
14
+ use Livewire\Attributes\Url;
15
+ use Livewire\Attributes\Computed;
14
16
15
17
class CustomerList extends Component
16
18
{
17
19
use WithPagination;
18
20
19
21
#[Validate('required|string|min:2')]
22
+ #[Url]
20
23
public string $search = '';
21
24
22
25
#[Validate('in:active,inactive,all')]
@@ -36,12 +39,11 @@ class CustomerList extends Component
36
39
37
40
public function render()
38
41
{
39
- return view('livewire.customer-list', [
40
- 'customers' => $this->getCustomers(),
41
- ]);
42
+ return view('livewire.customer-list');
42
43
}
43
44
44
- private function getCustomers()
45
+ #[Computed]
46
+ public function customers()
45
47
{
46
48
return Customer::query()
47
49
->when($this->search, fn($query) => $query->search($this->search))
You can’t perform that action at this time.
0 commit comments