File: /var/www/admin.fixgini.com/app/Livewire/User/Services.php
<?php
namespace App\Livewire\User;
use App\Models\Gig;
use Livewire\Component;
use Livewire\WithPagination;
class Services extends Component
{
use WithPagination;
public $search = '';
public $sortField = 'title';
public $sortDirection = 'asc';
public $perPage = 10;
public function sortBy($field)
{
$this->sortDirection = $this->sortField === $field
? ($this->sortDirection === 'asc' ? 'desc' : 'asc')
: 'asc';
$this->sortField = $field;
}
public function updatingSearch()
{
$this->resetPage();
}
public function render()
{
return view('livewire.user.services', [
'gigs' => Gig::query()
->with(['category', 'shop'])
->where(function ($query) { // Group the search conditions together
$query->where('title', 'like', '%' . $this->search . '%')
->orWhere('description', 'like', '%' . $this->search . '%');
})
->orderBy($this->sortField, $this->sortDirection)
->paginate($this->perPage),
]);
}
}