Refactor table components to use GenericTableSettings and remove deprecated classes

This commit is contained in:
David
2025-04-25 01:19:30 -04:00
parent 7466083798
commit 9f12bc28d0
17 changed files with 177 additions and 203 deletions

View File

@@ -3,27 +3,40 @@
namespace App\Tables;
use App\Models\Product;
use Illuminate\Database\Eloquent\Model;
use Mmt\GenericTable\Components\Column;
use Mmt\GenericTable\Components\ColumnCollection;
use Mmt\GenericTable\Enums\DatabaseEventQueryState;
use Mmt\GenericTable\Interfaces\IEvent;
use Mmt\GenericTable\Interfaces\IGenericTable;
use Mmt\GenericTable\Support\DatabaseEvent;
use Mmt\GenericTable\Support\GenericTableSettings;
class TableWithRelationships implements IGenericTable
class TableWithRelationships implements IGenericTable, IEvent
{
public Model|string $model;
public ColumnCollection $columns;
public GenericTableSettings $tableSettings;
public function __construct()
{
$this->model = new Product();
$this->columns = new ColumnCollection()->add(
$columns = new ColumnCollection()->add(
new Column('Name'),
new Column('Department', 'subDepartment.department.name'),
new Column('SubDepartment', 'subDepartment.name'),
new Column('Department'),
new Column('SubDepartment'),
);
$this->tableSettings = new GenericTableSettings(new Product(), $columns, true);
}
public function dispatchCallback(\Mmt\GenericTable\Support\EventArgs $arguments): void
{
if($arguments instanceof DatabaseEvent) {
if($arguments->queryState == DatabaseEventQueryState::INITIALIZING) {
$arguments->builder->join('sub_departments', 'sub_departments.id', 'products.sub_department_id')
->join('departments', 'departments.id', 'sub_departments.department_id')
->select(
'products.name as name',
'departments.name as department',
'sub_departments.name as sub_department'
);
}
}
}
}