LAR_Maintenance/app/Livewire/Host/DataTable.php

66 lines
1.5 KiB
PHP
Raw Normal View History

2024-07-30 16:13:21 +00:00
<?php
namespace App\Livewire\Host;
use App\Models\Host;
2024-08-16 16:20:45 +00:00
use App\Services\ZabbixService;
2024-07-30 16:13:21 +00:00
use SteelAnts\DataTable\Livewire\DataTableComponent;
use Illuminate\Database\Eloquent\Builder;
class DataTable extends DataTableComponent
{
public $listeners = [
'hostAdded' => '$refresh',
'closeModal' => '$refresh',
];
2024-08-16 16:20:45 +00:00
public bool $searchable = true;
public array $searchableColumns = ['display_name', 'hostname'];
2024-07-30 16:13:21 +00:00
public function query(): Builder
{
2024-09-25 20:09:13 +00:00
return Host::query()->with(['hostGroups']);
2024-07-30 16:13:21 +00:00
}
public function headers(): array
{
return [
2024-08-16 16:20:45 +00:00
'display_name' => 'display_name',
2024-07-30 16:13:21 +00:00
'hostname' => 'hostname',
2024-09-25 20:09:13 +00:00
'host_groups' => 'host_groups',
2024-07-30 16:13:21 +00:00
];
}
public function remove($host_id){
Host::find($host_id)->delete();
}
2024-09-25 20:09:13 +00:00
public function columnHostGroups(mixed $column): mixed
{
return implode(", " , $column->pluck('name')->toArray());
}
2024-07-30 16:13:21 +00:00
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]);
}
}