50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Tables\Traits;
|
|
|
|
use App\Models\Product;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Mmt\GenericTable\Attributes\CellFormatter;
|
|
use Mmt\GenericTable\Attributes\MappedColumn;
|
|
use Mmt\GenericTable\Components\Column;
|
|
use Mmt\GenericTable\Components\ColumnCollection;
|
|
use Mmt\GenericTable\Enums\ColumnSettingFlags;
|
|
|
|
trait WithColumnFormatter
|
|
{
|
|
public Model|string $model = Product::class;
|
|
|
|
public ColumnCollection $columns;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$this->columns = ColumnCollection::make(
|
|
new Column('Id'),
|
|
new Column('Name'),
|
|
new Column('Description'),
|
|
new Column('Price'),
|
|
new Column('Stock'),
|
|
new Column('SubDepartment', 'subDepartment.name'),
|
|
new Column('Empty Column')->withSettings(ColumnSettingFlags::EMPTY),
|
|
new Column('Empty Hook')->withSettings(ColumnSettingFlags::EMPTY)->hookFormatter(fn($rowModel) => $this->emptyCol($rowModel)),
|
|
);
|
|
}
|
|
|
|
public function emptyCol($model)
|
|
{
|
|
return '<i class = "text-danger">'.$model->id.'</i>';
|
|
}
|
|
|
|
#[CellFormatter('price')]
|
|
public function priceFormatter(Model $modelItem)
|
|
{
|
|
return "<b class = 'text-primary'>\$</b> {$modelItem->price}";
|
|
}
|
|
|
|
#[CellFormatter('id')]
|
|
public function idFormatter(Model $modelItem)
|
|
{
|
|
return '<b class = "text-primary">#</b> '.$modelItem->id;
|
|
}
|
|
} |