43 lines
1.0 KiB
PHP
43 lines
1.0 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;
|
|
|
|
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'),
|
|
);
|
|
}
|
|
|
|
|
|
#[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;
|
|
}
|
|
} |