Uploading content
This commit is contained in:
43
app/Tables/Traits/WithColumnFormatter.php
Normal file
43
app/Tables/Traits/WithColumnFormatter.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user