Fix bug on select2 in modal filters, add filters by tags and shelves on articles
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user