104 lines
3.3 KiB
PHP
104 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers\Article;
|
|
|
|
use App\Models\Article;
|
|
use App\Models\Category;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
|
|
class IndexController extends AdminController
|
|
{
|
|
|
|
protected $title = '内容管理';
|
|
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(Article::with(['category'])->latest('id'), function (Grid $grid) {
|
|
$grid->column('id', '#ID#');
|
|
$grid->column('cover', '封面图片')->image('', 60, 60);
|
|
|
|
$grid->column('category.title', '所属分类');
|
|
$grid->column('title', '文章标题');
|
|
$grid->column('sort', '序号');
|
|
$grid->status('状态')->switch();
|
|
|
|
$grid->column('created_at', '创建时间');
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->like('title', '文章标题');
|
|
$filter->equal('category.id', '所属分类')->select(Category::selectOptions(function ($model) {
|
|
return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
|
|
}, '所有分类'));
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new Article(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('title');
|
|
$show->field('category_id');
|
|
$show->field('description');
|
|
$show->field('cover');
|
|
$show->field('content');
|
|
$show->field('status');
|
|
$show->field('sort');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new Article(), function (Form $form) {
|
|
$form->text('title', '文章标题')->rules('min:2');
|
|
$form->select('category_id', '所属分类')
|
|
->options(Category::selectOptions(function ($model) {
|
|
return $model->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
|
|
}, '选择分类'))
|
|
->rules('required|min:1', [
|
|
'required' => '必须选择所属分类',
|
|
'min' => '必须选择所属分类',
|
|
]);
|
|
|
|
$form->textarea('description', '内容简介')->rules('max:350');
|
|
$form->image('cover', '封面')
|
|
->rules('image|mimes:jpeg,jpg,png')
|
|
->accept('jpeg,jpg,png')
|
|
->move('images/'.date('Y/m/d'))
|
|
->uniqueName();
|
|
|
|
$form->editor('content', '文章内容')
|
|
->rules('required', ['required' => '详情不能为空']);
|
|
$form->number('sort', '序号')
|
|
->default(0)
|
|
->rules('required', ['required' => '序号必须填写'])
|
|
->help('倒序优先');
|
|
$form->switch('status', '状态')->default(1);
|
|
$form->datetime('created_at', '发布时间')->default(now());
|
|
});
|
|
}
|
|
|
|
}
|