Files
generic_table_examples/app/Tables/TableWithRelationships.php
2025-05-03 01:57:26 -04:00

41 lines
1.2 KiB
PHP

<?php
namespace App\Tables;
use App\Models\Product;
use Mmt\GenericTable\Components\Column;
use Mmt\GenericTable\Components\ColumnCollection;
use Mmt\GenericTable\Interfaces\IExportable;
use Mmt\GenericTable\Interfaces\IGenericTable;
use Mmt\GenericTable\Support\GenericTableSettings;
class TableWithRelationships implements IGenericTable, IExportable
{
public GenericTableSettings $tableSettings;
public function __construct()
{
$columns = ColumnCollection::make(
new Column('Product Name', 'name')
->searchable()
->sortable(),
new Column('Department Name', 'subDepartment.department.name')
->searchable()
->sortable(),
new Column('SubDepartment Name', 'subDepartment.name')
->searchable()
->exportable()
->sortable(),
);
$this->tableSettings = new GenericTableSettings(new Product(), $columns);
}
public function onExport(\Mmt\GenericTable\Support\ExportEventArgs $args): \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse
{
$args->query->take(5);
return $args->export();
}
}