123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace App\Admin\Controllers;
- use App\School;
- 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 SchoolController 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 School);
- $grid->id("编号");
- $grid->name('学校全名');
- $grid->address('地址');
- $grid->nickname('简称');
- $grid->sclass("班级数量")->display(function ($sclass) {
- $count = count($sclass);
- return "<span class='label label-warning'>{$count}</span>";
- });
- $grid->disableExport();
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableView();
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(School::findOrFail($id));
- $show->id('编号');
- $show->name('学校全名');
- $show->address('地址');
- $show->nickname('简称');
- $show->created_at('创建时间');
- $show->updated_at('更新时间');
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new School);
- $form->text('name', '学校全名');
- $form->text('address', '学校地址');
- $form->text('nickname', '学校简称');
- $form->disableViewCheck();
- $form->disableEditingCheck();
- $form->disableCreatingCheck();
- $form->tools(function (Form\Tools $tools) {
- $tools->disableView();
- });
- return $form;
- }
- }
|