refactor datatables admin
This commit is contained in:
53
app/Datatables/Admin/Shop/MerchandisesDataTable.php
Normal file
53
app/Datatables/Admin/Shop/MerchandisesDataTable.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Datatables\Admin\Shop;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Repositories\Shop\Merchandises;
|
||||
use App\Repositories\Shop\Tags;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
class MerchandisesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'merchandises';
|
||||
|
||||
public function query(Merchandise $model)
|
||||
{
|
||||
$model = $model::with(['image', 'tags'])->withCount(['Articles', 'tags', 'images']);
|
||||
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('thumb', function (Merchandise $merchandise) {
|
||||
return Merchandises::getThumb($merchandise->image, false);
|
||||
})
|
||||
->editColumn('tags2', function (Merchandise $merchandise) {
|
||||
$html = '';
|
||||
foreach ($merchandise->tags as $tag) {
|
||||
$html .= Tags::getTagHtml($tag);
|
||||
}
|
||||
|
||||
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('articles_count')->title('#Art')->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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user