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 @@