123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- namespace App\Admin\Controllers;
- use App\Tool;
- use App\Http\Controllers\Controller;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- class ToolController 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 Tool);
- $grid->model()->orderBy('order', 'desc');
- $grid->id('Id');
- $grid->name('名称');
- $grid->url('连接');
- $grid->img('图片')->image('', 40);
- $grid->color('色值')->display(function ($v) {
- return '<span style="color: ' . $v . ';">' . $v . '</span>';
- });
- $grid->status('状态')->display(function ($v) {
- return $v ? '显示' : '隐藏';
- });;
- $grid->disableFilter();
- $grid->disableExport();
- $grid->disableCreateButton();
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableView();
- // $actions->disableDelete();
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(Tool::findOrFail($id));
- $show->id('Id');
- $show->name('Name');
- $show->url('Url');
- $show->img('Img');
- $show->color('Color');
- $show->status('Status');
- $show->created_at('Created at');
- $show->updated_at('Updated at');
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new Tool);
- $form->text('name', '名称');
- $form->image('img', '图片')->uniqueName()->help('尺寸建议:100px*100px');
- $form->url('url', '链接');
- $form->color('color', '颜色');
- $form->switch('status', '是否显示')->default(1);
- $form->number('order', '排序')->default(0);
- return $form;
- }
- }
|