Files
opensem/app/Datatables/Shop/ProducersDataTable.php
Ludovic CANDELLIER d8bf91da54 Add plus on products
2022-04-25 20:02:28 +02:00

52 lines
1.7 KiB
PHP

<?php
namespace App\Datatables\Shop;
use Yajra\DataTables\Html\Column;
use App\Datatables\ParentDataTable as DataTable;
use App\Models\Shop\Producer;
use App\Repositories\Shop\Producers;
class ProducersDataTable extends DataTable
{
public $model_name = 'producers';
public function query(Producer $model)
{
$model = $model::with(['image', 'tags'])->withCount(['Merchandises', 'tags', 'images']);
return $this->buildQuery($model);
}
public function modifier($datatables)
{
$datatables
->editColumn('thumb', function (Producer $producer) {
return $producer->image ? Producers::getThumb($producer->image) : '';
})
->editColumn('tags2', function (Producer $producer) {
$html = '';
foreach ($producer->tags as $tag) {
$html .= '<span class="btn btn-xs btn-secondary pb-2">' . $tag->slug . '</span> ';
}
return $html;
})
->rawColumns(['thumb', 'tags2', 'action']);
return parent::modifier($datatables);
}
protected function getColumns()
{
return [
Column::make('thumb')->title('')->searchable(false)->orderable(false)->width(40)->class('text-center'),
Column::make('name')->title('Nom'),
Column::make('tags2')->title('Tags')->searchable(false)->orderable(false),
Column::make('merchandises_count')->title('#Mar')->class('text-right')->searchable(false),
Column::make('tags_count')->title('#Tag')->class('text-right')->searchable(false),
Column::make('images_count')->title('#Pho')->class('text-right')->searchable(false),
$this->makeColumnButtons(),
];
}
}