|
@@ -0,0 +1,95 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace App\Admin\Controllers;
|
|
|
|
+
|
|
|
|
+use App\Models\Banner;
|
|
|
|
+use Encore\Admin\Controllers\AdminController;
|
|
|
|
+use Encore\Admin\Form;
|
|
|
|
+use Encore\Admin\Grid;
|
|
|
|
+use Encore\Admin\Show;
|
|
|
|
+
|
|
|
|
+class BannerController extends AdminController
|
|
|
|
+{
|
|
|
|
+ /**
|
|
|
|
+ * Title for current resource.
|
|
|
|
+ *
|
|
|
|
+ * @var string
|
|
|
|
+ */
|
|
|
|
+ protected $title = 'Banner';
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Make a grid builder.
|
|
|
|
+ *
|
|
|
|
+ * @return Grid
|
|
|
|
+ */
|
|
|
|
+ protected function grid()
|
|
|
|
+ {
|
|
|
|
+ $grid = new Grid(new Banner());
|
|
|
|
+
|
|
|
|
+ $grid->column('id', __('Id'));
|
|
|
|
+ $grid->column('image', __('图片'))->image('',100,100);
|
|
|
|
+ $grid->column('type','类型')->using([1=>'用户端',2=>'医生端']);
|
|
|
|
+ $grid->column('url', __('链接'));
|
|
|
|
+ $states = [
|
|
|
|
+ 'on' => ['value' => 1, 'text' => '启用', 'color' => 'success'],
|
|
|
|
+ 'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
|
|
|
|
+ ];
|
|
|
|
+ $grid->column('status','状态')->switch($states);
|
|
|
|
+ $grid->column('created_at', __('创建时间'));
|
|
|
|
+ $grid->column('updated_at', __('更新时间'));
|
|
|
|
+ $grid->filter(function($filter){
|
|
|
|
+
|
|
|
|
+ // Remove the default id filter
|
|
|
|
+ $filter->disableIdFilter();
|
|
|
|
+
|
|
|
|
+ // Add a column filter
|
|
|
|
+ $type = [''=>'全部'];
|
|
|
|
+ $type = array_merge($type,Banner::$_post_type);
|
|
|
|
+ $filter->equal('type', '类别')->select(Banner::$_post_type);
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return $grid;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Make a show builder.
|
|
|
|
+ *
|
|
|
|
+ * @param mixed $id
|
|
|
|
+ * @return Show
|
|
|
|
+ */
|
|
|
|
+ protected function detail($id)
|
|
|
|
+ {
|
|
|
|
+ $show = new Show(Banner::findOrFail($id));
|
|
|
|
+
|
|
|
|
+ $show->field('id', __('Id'));
|
|
|
|
+ $show->field('image', __('Image'))->image('',100,100);
|
|
|
|
+ $show->field('url', __('Url'));
|
|
|
|
+ $show->field('status', __('Status'));
|
|
|
|
+ $show->field('updated_at', __('Updated at'));
|
|
|
|
+ $show->field('created_at', __('Created at'));
|
|
|
|
+
|
|
|
|
+ return $show;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Make a form builder.
|
|
|
|
+ *
|
|
|
|
+ * @return Form
|
|
|
|
+ */
|
|
|
|
+ protected function form()
|
|
|
|
+ {
|
|
|
|
+ $form = new Form(new Banner());
|
|
|
|
+
|
|
|
|
+ $form->select('type' ,__('分类'))->options(Banner::$_post_type)->default('1');
|
|
|
|
+ $form->image('image', __('图片'))->rules('required' ,['required'=>'请选择图片!']);
|
|
|
|
+ $form->text('url', __('链接'));
|
|
|
|
+ $states = [
|
|
|
|
+ 'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
|
|
|
|
+ 'on' => ['value' => 1, 'text' => '启用', 'color' => 'success'],
|
|
|
|
+ ];
|
|
|
|
+ $form->switch('status','状态')->states($states);
|
|
|
|
+
|
|
|
|
+ return $form;
|
|
|
|
+ }
|
|
|
|
+}
|