文章对应分类多个

This commit is contained in:
2021-04-02 10:15:47 +08:00
parent 5e1c402087
commit ead950990f
12 changed files with 324 additions and 180 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Admin\Selectable;
use App\Models\Category;
use Encore\Admin\Grid\Filter;
use Encore\Admin\Grid\Selectable;
class CategorySelectAble extends Selectable
{
public $model = Category::class;
public static function display()
{
return function ($value) {
if (is_array($value)) {
return implode(';', array_column($value, 'title'));
}
return optional($this->categories)->title;
};
}
public function make()
{
$this->model()->where('status', 1);
$this->column('id', 'ID');
$this->column('title', '分类名称');
$this->column('type', '类型')->using(Category::TYPES);
$this->filter(function (Filter $filter) {
$filter->like('title', '分类名称');
$filter->equal('parent.id', '所属分类')
->select(Category::selectOptions(function ($model) {
return $model->where('status', 1)
->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
}, '所有分类'));
$filter->equal('type', '类型')->select(Category::TYPES);
});
}
}