139 lines
3.1 KiB
PHP
139 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Explain;
|
|
use Encore\Admin\Controllers\HasResourceActions;
|
|
use Encore\Admin\Form;
|
|
use Encore\Admin\Grid;
|
|
use Encore\Admin\Layout\Content;
|
|
use Encore\Admin\Show;
|
|
|
|
class ExplainController extends Controller
|
|
{
|
|
use HasResourceActions;
|
|
|
|
/**
|
|
* Index interface.
|
|
*
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
public function index(Content $content)
|
|
{
|
|
return $content
|
|
->header('解读管理')
|
|
->description('列表')
|
|
->body($this->grid());
|
|
}
|
|
|
|
/**
|
|
* Show interface.
|
|
*
|
|
* @param mixed $id
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
public function show($id, Content $content)
|
|
{
|
|
return $content
|
|
->header('解读管理')
|
|
->description('详情')
|
|
->body($this->detail($id));
|
|
}
|
|
|
|
/**
|
|
* Edit interface.
|
|
*
|
|
* @param mixed $id
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
public function edit($id, Content $content)
|
|
{
|
|
return $content
|
|
->header('解读管理')
|
|
->description('编辑')
|
|
->body($this->form()->edit($id));
|
|
}
|
|
|
|
/**
|
|
* Create interface.
|
|
*
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
public function create(Content $content)
|
|
{
|
|
return $content
|
|
->header('解读管理')
|
|
->description('创建')
|
|
->body($this->form());
|
|
}
|
|
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
$grid = new Grid(new Explain);
|
|
|
|
$grid->id('ID');
|
|
$grid->title('标题');
|
|
$grid->description('简介');
|
|
$grid->status('状态')->switch();
|
|
$grid->order('排序');
|
|
|
|
$grid->filter(function ($filter) {
|
|
// 去掉默认的id过滤器
|
|
$filter->disableIdFilter();
|
|
// 在这里添加字段过滤器
|
|
$filter->like('title', '标题');
|
|
});
|
|
return $grid;
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
$show = new Show(Explain::findOrFail($id));
|
|
|
|
$show->id('ID');
|
|
$show->title('标题');
|
|
$show->description('简介');
|
|
$show->content('详情');
|
|
$show->status('状态')->using(['1' => '正常', '0' => '关闭']);
|
|
$show->order('排序');
|
|
$show->clicks('浏览量');
|
|
|
|
return $show;
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
$form = new Form(new Explain);
|
|
|
|
$form->text('title', '标题')->rules('required');
|
|
$form->textarea('description', '简介');
|
|
$form->editor('content', '详情')->rules('required', ['required' => '详情不能为空']);
|
|
$form->switch('status', '状态')->default(1);
|
|
$form->number('order', '排序')->default(0);
|
|
$form->number('clicks', '浏览量')->default(0);
|
|
|
|
return $form;
|
|
}
|
|
}
|