Files
opensem/app/Datatables/Shop/ArticlesDataTable.php
2021-08-30 22:59:50 +02:00

39 lines
1.4 KiB
PHP

<?php
namespace App\Datatables\Shop;
use Yajra\DataTables\Html\Column;
use App\Datatables\ParentDataTable as DataTable;
use App\Models\Shop\Article;
class ArticlesDataTable extends DataTable
{
public $model_name = 'articles';
public $sortedColumn = 1;
public function query(Article $model)
{
// $model = $model::with('Family')->select('shop_articles.*','family.name as family_name')->join('shop_article_families as family', 'family.id', '=', 'shop_articles.article_family_id')->groupBy('shop_articles.id');
// $model = $model::with('article_nature')->select('shop_articles.*');
$model = $model::with('article_nature')->joinRelationship('article_nature')->select('shop_articles.*','shop_article_natures.name as nature_name');
$model = self::filterByArticleNature($model);
return self::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;
}
protected function getColumns()
{
return [
Column::make('article_nature.name')->data('nature_name')->title('Nature'),
Column::make('name')->title('Nom'),
self::makeColumnButtons(),
];
}
}