64 lines
2.4 KiB
PHP
64 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Datatables\Shop;
|
|
|
|
use Yajra\DataTables\Html\Column;
|
|
|
|
use App\Datatables\ParentDataTable as DataTable;
|
|
use App\Models\Shop\Article;
|
|
use App\Repositories\Shop\Articles;
|
|
|
|
class ArticlesDataTable extends DataTable
|
|
{
|
|
public $model_name = 'articles';
|
|
public $sortedColumn = 2;
|
|
|
|
public function query(Article $model)
|
|
{
|
|
$model = $model::with(['article_nature', 'image'])->withCount(['categories', 'images', 'offers', 'tags']);
|
|
$model = self::filterByArticleNature($model);
|
|
return $this->buildQuery($model);
|
|
}
|
|
|
|
public static function filterByArticleNature($model, $article_nature_id = false)
|
|
{
|
|
$article_nature_id = $article_nature_id ? $article_nature_id : self::isFilteredByField('article_nature_id');
|
|
return $article_nature_id ? $model->byArticleNature($article_nature_id) : $model;
|
|
}
|
|
|
|
public function modifier($datatables)
|
|
{
|
|
$datatables
|
|
->editColumn('thumb', function (Article $article) {
|
|
return '<img src="' . Articles::getThumbSrc($article->image) . '">';
|
|
})
|
|
->editColumn('article_nature.name', function (Article $article) {
|
|
return $article->article_nature ? $article->article_nature->name : '';
|
|
})
|
|
->editColumn('tags2', function (Article $article) {
|
|
$html = '';
|
|
foreach ($article->tags as $tag) {
|
|
$html .= '<span class="btn btn-xs btn-secondary pb-2">' . $tag->slug . '</span> ';
|
|
}
|
|
return $html;
|
|
})
|
|
->rawColumns(['tags2', 'thumb', 'action']);
|
|
return parent::modifier($datatables);
|
|
}
|
|
|
|
protected function getColumns()
|
|
{
|
|
return [
|
|
Column::make('article_nature.name')->title('Nature'),
|
|
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('tags_count')->title('#Tag')->class('text-right')->searchable(false),
|
|
Column::make('categories_count')->title('#Ray')->class('text-right')->searchable(false),
|
|
Column::make('offers_count')->title('#Ofr')->class('text-right')->searchable(false),
|
|
Column::make('images_count')->title('#Pho')->class('text-right')->searchable(false),
|
|
$this->makeColumnButtons(),
|
|
];
|
|
}
|
|
}
|