Fixes for deliveries vs sale_channels
This commit is contained in:
@@ -12,15 +12,42 @@ class CategoriesDataTable extends DataTable
|
||||
|
||||
public function query(Category $model)
|
||||
{
|
||||
$model = $model::withCount('articles');
|
||||
$model = $model::with(['tags.articles'])->withCount(['articles', 'tags']);
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('visible', function (Category $category) {
|
||||
return view("components.form.toggle", [
|
||||
'value' => $category->visible,
|
||||
'on' => __('visible'),
|
||||
'off' => __('invisible'),
|
||||
'meta' => 'data-id=' . $category->id,
|
||||
'size' => 'sm',
|
||||
]);
|
||||
})
|
||||
->editColumn('articles_tagged_count', function (Category $category) {
|
||||
$count = 0;
|
||||
foreach ($category->tags as $tag) {
|
||||
$nb = collect($tag->articles)->count();
|
||||
$count += $nb;
|
||||
}
|
||||
return $count;
|
||||
})
|
||||
->rawColumns(['visible', 'action']);
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('visible')->title('visible')->width(60)->title(''),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('articles_count')->title('Nb Articles')->class('text-right')->searchable(false),
|
||||
Column::make('articles_count')->title('#Art')->class('text-right')->searchable(false)->width(60),
|
||||
Column::make('tags_count')->title('#Tags')->class('text-right')->searchable(false)->width(60),
|
||||
Column::make('articles_tagged_count')->title('#ArtTag')->class('text-right')->searchable(false)->width(60),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user