12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Admin\Controllers;
- use Encore\Admin\Controllers\AdminController;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Show;
- use App\Models\SpecialistCloumn;
- class SpecialistColumnController extends AdminController
- {
- /**
- * Title for current resource.
- *
- * @var string
- */
- protected $title = '健康课堂-一级栏目管理';
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new SpecialistCloumn);
- // 禁用创建按钮
- // $grid->disableCreateButton();
- // 禁用编辑功能
- // $grid->disableActions();
- $grid->column('id', __('ID'))->sortable();
- $grid->column('name', __('名称'));
- $grid->column('is_show', __('是否显示'));
- // ->display(function ($isShow) {
- // return SpecialistCloumn::$isShowMap[$isShow];
- // });
- $grid->column('rank', __('排序(越大越靠前)'))->sortable();
- $grid->column('created_at', __('创建时间'));
- $grid->column('updated_at', __('更新时间'));
- $grid->model()->where('pid', SpecialistCloumn::PID_0);
- // 新增过滤
- $grid->filter(function ($filter) {
- $filter->like('name', '名称');
- $filter->equal('is_show', '是否显示')->radio(SpecialistCloumn::$isShowMap);
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(SpecialistCloumn::findOrFail($id));
- $show->field('id', __('ID'));
- $show->field('created_at', __('Created at'));
- $show->field('updated_at', __('Updated at'));
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new SpecialistCloumn);
- $form->display('id', __('ID'))->rules('required');
- $form->text('name', __('名称'))->rules('required');
- $form->image('pic', __('图片'))->uniqueName()->move('pics/'.date('Y').'/'.date('m'))->rules('required');
- $form->text('url', __('链接地址'))->rules('required');
- $form->table('banner', function ($table) {
- $table->image('src', '广告图')->uniqueName()->move('pics/'.date('Y').'/'.date('m'))->rules('required');
- $table->text('url', '链接地址')->rules('required');
- });
- $states = [
- 'on' => ['value' => 1, 'text' => '显示', 'color' => 'success'],
- 'off' => ['value' => 0, 'text' => '不显示', 'color' => 'danger'],
- ];
- $form->switch('is_show', __('是否显示'))->states($states);
- $form->number('rank', __('排序(越大越靠前)'))->default(0);
- return $form;
- }
- }
|