LAR_Maintenance/app/Livewire/HostGroup/DataTable.php
2024-09-25 22:09:13 +02:00

60 lines
1.3 KiB
PHP

<?php
namespace App\Livewire\HostGroup;
use App\Models\HostGroup;
use SteelAnts\DataTable\Livewire\DataTableComponent;
use Illuminate\Database\Eloquent\Builder;
class DataTable extends DataTableComponent
{
public $listeners = [
'hostgroupAdded' => '$refresh',
'closeModal' => '$refresh',
];
public function query(): Builder
{
return HostGroup::query()->with(['hosts:id']);
}
public function headers(): array
{
return [
'name' => 'name',
'hosts_count' => 'hosts_count',
];
}
public function row($row){
$row['hosts_count'] = $row->hosts->count();
return $row;
}
public function remove($hostgroup_id){
HostGroup::find($hostgroup_id)->delete();
}
public function actions($item)
{
return [
[
'type' => "livewire",
'action' => "edit",
'text' => "edit",
'parameters' => $item['id']
],
[
'type' => "livewire",
'action' => "remove",
'text' => "remove",
'parameters' => $item['id']
]
];
}
public function edit($host_id)
{
$this->dispatch('openModal', 'host.form', __('boilerplate::host.edit'), ['model' => $host_id]);
}
}