When to use me
- Creating a listing/index page for a resource
- Building the main entry point for browsing records
- User asks for searchable, sortable, or paginated lists
Related skills
- livewire-resource-config
- livewire-form-component
Implementation
Base structure
use App\Models\Model;
use Naykel\Gotime\Livewire\BaseIndex;
new class extends BaseIndex
{
protected string $modelClass = Model::class;
protected function configKey(): string
{
return 'resource';
}
protected function query($query)
{
return $query;
}
}
Features
Search
- If config has
searchableFields, addSearchabletrait - Apply search in query method:
protected function query($query)
{
$query = $this->applySearch($query);
return $query;
}
Sort
- If config has
sortColumn, addSortabletrait - Apply sorting in query method:
protected function query($query)
{
$query = $this->applySorting($query);
return $query;
}
sortDirectionis automatically applied by trait
Combining features
use Naykel\Gotime\Traits\Searchable;
use Naykel\Gotime\Traits\Sortable;
new class extends BaseIndex
{
use Searchable, Sortable;
protected function query($query)
{
$query = $this->applySorting($query);
$query = $this->applySearch($query);
return $query;
}
}