LAR_Maintenance/app/Livewire/User/DataTable.php

52 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2024-07-30 16:13:21 +00:00
<?php
namespace App\Livewire\User;
use App\Models\User;
use SteelAnts\DataTable\Livewire\DataTableComponent;
use Illuminate\Database\Eloquent\Builder;
class DataTable extends DataTableComponent
{
public $listeners = [
'userAdded' => '$refresh'
];
public function query(): Builder
{
return User::query();
}
public function headers(): array
{
return [
'id' => 'ID',
'name' => 'Name',
'email' => 'E-mail',
];
}
public function actions($item)
{
if ($item['id'] == auth()->user()->id) {
return [];
}
return [
[
'type' => "livewire",
'action' => "remove",
'parameters' => $item['id'],
'text' => "Remove",
'actionClass' => 'text-danger',
'iconClass' => 'fas fa-trash',
]
];
}
public function remove($user_id)
{
User::find($user_id)->delete();
}
}