Functioning client list
This commit is contained in:
parent
bfb943af62
commit
428e5ba3a0
|
|
@ -2,36 +2,61 @@
|
||||||
|
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
use Livewire\Attributes\Computed;
|
||||||
|
use Livewire\WithPagination;
|
||||||
|
|
||||||
|
|
||||||
new class extends Component {
|
new class extends Component {
|
||||||
|
use WithPagination;
|
||||||
|
|
||||||
|
public string $sortBy = 'abbreviation';
|
||||||
|
public string $sortDirection = 'desc';
|
||||||
|
|
||||||
|
public function sort($column): void
|
||||||
|
{
|
||||||
|
if ($this->sortBy === $column) {
|
||||||
|
$this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc';
|
||||||
|
} else {
|
||||||
|
$this->sortBy = $column;
|
||||||
|
$this->sortDirection = 'asc';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
public function clients()
|
public function clients()
|
||||||
{
|
{
|
||||||
return Client::all();
|
return Client::orderBy($this->sortBy, $this->sortDirection)->paginate(10);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<flux:table>
|
<flux:table :paginate="$this->clients">
|
||||||
<flux:table.columns>
|
<flux:table.columns>
|
||||||
<flux:table.column>Name</flux:table.column>
|
<flux:table.column sortable :sorted="$sortBy === 'name'" :direction="$sortDirection"
|
||||||
<flux:table.column>
|
wire:click="sort('name')">
|
||||||
|
Name
|
||||||
|
</flux:table.column>
|
||||||
|
<flux:table.column sortable :sorted="$sortBy === 'abbreviation'" :direction="$sortDirection"
|
||||||
|
wire:click="sort('abbreviation')">
|
||||||
Abbreviation
|
Abbreviation
|
||||||
</flux:table.column>
|
</flux:table.column>
|
||||||
<flux:table.column>
|
<flux:table.column sortable :sorted="$sortBy === 'audition_date'" :direction="$sortDirection"
|
||||||
|
wire:click="sort('audition_date')">
|
||||||
Audition Date
|
Audition Date
|
||||||
</flux:table.column>
|
</flux:table.column>
|
||||||
<flux:table.column>
|
<flux:table.column sortable :sorted="$sortBy === 'status'" :direction="$sortDirection"
|
||||||
|
wire:click="sort('status')">
|
||||||
Status
|
Status
|
||||||
</flux:table.column>
|
</flux:table.column>
|
||||||
<flux:table.column>
|
<flux:table.column sortable :sorted="$sortBy === 'created_at'" :direction="$sortDirection"
|
||||||
|
wire:click="sort('created_at')">
|
||||||
Created
|
Created
|
||||||
</flux:table.column>
|
</flux:table.column>
|
||||||
</flux:table.columns>
|
</flux:table.columns>
|
||||||
|
|
||||||
<flux:table.rows>
|
<flux:table.rows>
|
||||||
@foreach($this->clients() as $client)
|
@foreach($this->clients as $client)
|
||||||
<flux:table.row :key="$client->id">
|
<flux:table.row :key="$client->id">
|
||||||
<flux:table.cell>{{ $client->name }}</flux:table.cell>
|
<flux:table.cell>{{ $client->name }}</flux:table.cell>
|
||||||
<flux:table.cell>{{ $client->abbreviation }}</flux:table.cell>
|
<flux:table.cell>{{ $client->abbreviation }}</flux:table.cell>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue