LAR_Maintenance/app/Livewire/Task/DataTable.php

60 lines
1.3 KiB
PHP

<?php
namespace App\Livewire\Task;
use App\Models\Task;
use SteelAnts\DataTable\Livewire\DataTableComponent;
use Illuminate\Database\Eloquent\Builder;
class DataTable extends DataTableComponent
{
public $listeners = [
'taskAdded' => '$refresh',
'closeModal' => '$refresh',
];
public function query(): Builder
{
return Task::query();
}
public function headers(): array
{
return [
'name' => 'name',
'description' => 'description',
];
}
public function renderColumnDescription($value, $row)
{
return e(!empty($value) ? mb_strimwidth(strip_tags($value), 0, 50, "...") : "");
}
public function remove($task_id){
Task::find($task_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($task_id)
{
$this->dispatch('openModal', 'task.form', __('boilerplate::task.edit'), ['model' => $task_id]);
}
}