SuperAPI AI Directory

livewire-index-component

Coding & development

View repository

Updated 10-16 06:50

About this skill

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`, add `Searchable` trait
- Apply search in query method:

```php +code
  protected function query($query)
  {
      $query = $this->applySearch($query);
      return $query;
  }

Sort

  • If config has sortColumn, add Sortable trait
  • Apply sorting in query method:
  protected function query($query)
  {
      $query = $this->applySorting($query);
      return $query;
  }
  • sortDirection is 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;
    }
}