diff --git a/app/Datatables/Shop/ArticlesDataTable.php b/app/Datatables/Shop/ArticlesDataTable.php index 8b8f6405..56cfec88 100644 --- a/app/Datatables/Shop/ArticlesDataTable.php +++ b/app/Datatables/Shop/ArticlesDataTable.php @@ -17,6 +17,8 @@ class ArticlesDataTable extends DataTable { $model = $model::with(['article_nature', 'image'])->withCount(['categories', 'images', 'offers', 'tags']); $model = self::filterByArticleNature($model); + $model = self::filterByCategory($model); + $model = self::filterByTag($model); return $this->buildQuery($model); } @@ -26,6 +28,18 @@ class ArticlesDataTable extends DataTable return $article_nature_id ? $model->byArticleNature($article_nature_id) : $model; } + public static function filterByCategory($model, $category_id = false) + { + $category_id = $category_id ? $category_id : self::isFilteredByField('category_id'); + return $category_id ? $model->byCategory($category_id) : $model; + } + + public static function filterByTag($model, $tag_id = false) + { + $tag_id = $tag_id ? $tag_id : self::isFilteredByField('tag_id'); + return $tag_id ? $model->byTag($tag_id) : $model; + } + public function modifier($datatables) { $datatables diff --git a/app/Http/Controllers/Admin/Shop/ArticleController.php b/app/Http/Controllers/Admin/Shop/ArticleController.php index b30860b6..e9376b0b 100644 --- a/app/Http/Controllers/Admin/Shop/ArticleController.php +++ b/app/Http/Controllers/Admin/Shop/ArticleController.php @@ -6,6 +6,9 @@ use Illuminate\Http\Request; use App\Repositories\Shop\Articles; use App\Repositories\Shop\ArticleNatures; +use App\Repositories\Shop\Categories; +use App\Repositories\Shop\Tags; + use App\Datatables\Shop\ArticlesDataTable; class ArticleController extends Controller @@ -19,6 +22,8 @@ class ArticleController extends Controller public function index(ArticlesDataTable $dataTable) { $data['article_natures'] = ArticleNatures::getOptions(); + $data['categories'] = Categories::getOptions(); + $data['tags'] = Tags::getOptionsFullName(); return $dataTable->render('Admin.Shop.Articles.list', $data); } diff --git a/app/Repositories/Shop/Tags.php b/app/Repositories/Shop/Tags.php index 3dcb8c03..9f6b49ec 100644 --- a/app/Repositories/Shop/Tags.php +++ b/app/Repositories/Shop/Tags.php @@ -27,9 +27,9 @@ class Tags public static function getOptionsFullName() { - $tags = Tag::with('group')->get(); + $tags = Tag::with('group')->get()->toArray(); foreach ($tags as $tag) { - $data[$tag->id] = $tag->group->name . '-' . $tag->name; + $data[$tag['id']] = $tag['group']['name'] . '-' . $tag['name']; } return $data; } diff --git a/resources/views/Admin/Shop/Articles/partials/filters.blade.php b/resources/views/Admin/Shop/Articles/partials/filters.blade.php index ff7966da..ee7dae8c 100644 --- a/resources/views/Admin/Shop/Articles/partials/filters.blade.php +++ b/resources/views/Admin/Shop/Articles/partials/filters.blade.php @@ -1,8 +1,20 @@
-
+
@include('components.form.select', ['name' => 'article_nature_id', 'list' => $article_natures ?? [], 'value' => $filters['article_nature_id'] ?? null, 'class' => 'form-control-sm select2', 'with_empty' => ' '])
+
+ +
+ @include('components.form.select', ['name' => 'category_id', 'list' => $categories ?? [], 'value' => $filters['category_id'] ?? null, 'class' => 'form-control-sm select2', 'with_empty' => ' ']) +
+
+
+ +
+ @include('components.form.select', ['name' => 'tag_id', 'list' => $tags ?? [], 'value' => $filters['tag_id'] ?? null, 'class' => 'form-control-sm select2', 'with_empty' => ' ']) +
+
diff --git a/resources/views/components/datatables/buttons/filters.blade.php b/resources/views/components/datatables/buttons/filters.blade.php index 387d455f..0ce0fa74 100644 --- a/resources/views/components/datatables/buttons/filters.blade.php +++ b/resources/views/components/datatables/buttons/filters.blade.php @@ -9,7 +9,7 @@ var $filter = $('#{{ $model ?? null }}-table-header .btn-filter'); $('#modal-{{ $model ?? null }}-filters').on('shown.bs.modal', function () { - initSelect2(); + initSelect2('.select2', '#modal-{{ $model ?? null }}-filters'); }); $('#modal-{{ $model ?? null }}-filters .apply').click(function() { diff --git a/resources/views/load/form/select2.blade.php b/resources/views/load/form/select2.blade.php index e8b46201..e5baf78e 100644 --- a/resources/views/load/form/select2.blade.php +++ b/resources/views/load/form/select2.blade.php @@ -4,25 +4,43 @@ @endpush