Refactor table components to use GenericTableSettings and remove deprecated classes
This commit is contained in:
@@ -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'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user