LAR_Maintenance/app/Livewire/Task/DataTable.php

60 lines
1.3 KiB
PHP
Raw Normal View History

2024-08-06 06:31:51 +00:00
<?php
2024-08-06 09:02:45 +00:00
namespace App\Livewire\Task;
2024-08-06 06:31:51 +00:00
2024-08-06 09:02:45 +00:00
use App\Models\Task;
2024-08-06 06:31:51 +00:00
use SteelAnts\DataTable\Livewire\DataTableComponent;
use Illuminate\Database\Eloquent\Builder;
class DataTable extends DataTableComponent
{
public $listeners = [
2024-08-06 09:02:45 +00:00
'taskAdded' => '$refresh',
2024-08-06 06:31:51 +00:00
'closeModal' => '$refresh',
];
public function query(): Builder
{
2024-08-06 09:02:45 +00:00
return Task::query();
2024-08-06 06:31:51 +00:00
}
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, "...") : "");
}
2024-08-06 09:02:45 +00:00
public function remove($task_id){
Task::find($task_id)->delete();
2024-08-06 06:31:51 +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']
]
];
}
2024-08-06 09:02:45 +00:00
public function edit($task_id)
2024-08-06 06:31:51 +00:00
{
2024-08-06 09:02:45 +00:00
$this->dispatch('openModal', 'task.form', __('boilerplate::task.edit'), ['model' => $task_id]);
2024-08-06 06:31:51 +00:00
}
}