104 lines
2.9 KiB
PHP
104 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Admin;
|
|
|
|
use Spatie\Permission\Models\Role;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use PowerComponents\LivewirePowerGrid\Button;
|
|
use PowerComponents\LivewirePowerGrid\Column;
|
|
use PowerComponents\LivewirePowerGrid\Facades\Filter;
|
|
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
|
|
use PowerComponents\LivewirePowerGrid\PowerGridFields;
|
|
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
|
|
|
|
final class RoleTable extends PowerGridComponent
|
|
{
|
|
public string $tableName = 'role-table';
|
|
|
|
public function boot(): void
|
|
{
|
|
config(['livewire-powergrid.filter' => 'outside']);
|
|
}
|
|
|
|
public function setUp(): array
|
|
{
|
|
//$this->showCheckBox();
|
|
|
|
return [
|
|
//PowerGrid::header()
|
|
// ->showSearchInput(),
|
|
//PowerGrid::footer()
|
|
// ->showPerPage()
|
|
// ->showRecordCount(),
|
|
];
|
|
}
|
|
|
|
public function datasource(): Builder
|
|
{
|
|
//dd(Role::with('permissions'));
|
|
return Role::with('permissions');
|
|
}
|
|
|
|
public function relationSearch(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function fields(): PowerGridFields
|
|
{
|
|
return PowerGrid::fields()
|
|
->add('id')
|
|
->add('name')
|
|
->add('permissions_list' ,fn(Role $model)=> $model->permissions->pluck('name')->implode(', '))
|
|
->add('created_at_formatted', fn (Role $model) => Carbon::parse($model->created_at)->format('d/m/Y H:i:s'));
|
|
}
|
|
|
|
public function columns(): array
|
|
{
|
|
return [
|
|
Column::make(__('roles.no'), 'id')->sortable()->searchable(),
|
|
Column::make(__('roles.name'), 'name')->sortable()->searchable(),
|
|
Column::make(__('roles.permissions'), 'permissions_list'),
|
|
Column::make('Created at', 'created_at_formatted', 'created_at')->sortable(),
|
|
Column::action('Action')
|
|
];
|
|
}
|
|
|
|
public function filters(): array
|
|
{
|
|
return [
|
|
Filter::datetimepicker('created_at'),
|
|
];
|
|
}
|
|
|
|
|
|
public function actions(Role $row): array
|
|
{
|
|
return [
|
|
Button::add('edit')
|
|
->slot(__('roles.edit'))
|
|
->icon('solid-pencil-square')
|
|
->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
|
|
->dispatchTo('admin.role-form', 'openEditRoleModal', ['id' => $row->id]),
|
|
Button::add('delete')
|
|
->slot(__('delete'))
|
|
->icon('solid-trash')
|
|
->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
|
|
->dispatchTo('admin.role-form', 'deleteRole', ['id' => $row->id]),
|
|
];
|
|
}
|
|
|
|
/*
|
|
public function actionRules($row): array
|
|
{
|
|
return [
|
|
// Hide button edit for ID 1
|
|
Rule::button('edit')
|
|
->when(fn($row) => $row->id === 1)
|
|
->hide(),
|
|
];
|
|
}
|
|
*/
|
|
}
|