Last active
October 2, 2023 22:49
-
-
Save antonioanerao/7e24216c601d2eb31b8a631ce83e25a6 to your computer and use it in GitHub Desktop.
Laravel Livewire product component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Livewire; | |
| use Livewire\Component; | |
| use Livewire\WithPagination; | |
| class Product extends Component | |
| { | |
| use WithPagination; | |
| protected $paginationTheme = 'bootstrap'; | |
| public string $searchQuery = ''; | |
| public int $currentPage; | |
| public function render() | |
| { | |
| $this->searchQuery == '' ? $this->currentPage = 0 : $this->currentPage = 1; | |
| $products = \App\Models\Product::when($this->searchQuery != '', function($query) { | |
| $query->where('name', 'like', '%'.$this->searchQuery.'%'); | |
| }) | |
| ->paginate(10, ['*'], 'page', $this->currentPage); | |
| return view('livewire.product', compact('products')); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment