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->editForm()->edit($id)); } /** * Create interface. * * @param Content $content * @return Content */ public function create(Content $content) { return $content ->header('短信规则创建') ->description('') ->body($this->createForm()); } /** * Make a grid builder. * * @return Grid */ protected function grid() { $grid = new Grid(new SmsRule); $grid->id('ID'); $grid->name('规则名称')->width(200); $grid->alias('别名')->width(200); $states = [ 'on' => ['value' => 1, 'text' => '开启', 'color' => 'primary'], 'off' => ['value' => 0, 'text' => '关闭', 'color' => 'default'], ]; $grid->status('状态')->switch($states); $grid->created_at('添加时间'); $grid->updated_at('更新时间'); $grid->actions(function ($actions) { if (Admin::user()->can('system_sms_ruleM_edit')) { $actions->disableEdit(false); } $actions->disableDelete(false); }); if (Admin::user()->can('system_sms_ruleM_create')) { $grid->disableCreateButton(false); } return $grid; } /** * Make a show builder. * * @param mixed $id * @return Show */ protected function detail($id) { $show = new Show(SmsRule::findOrFail($id)); $show->id('ID'); $show->name('规则名称'); $show->alias('别名'); $show->status('状态')->as(function ($status) { if ($status) { return '开启'; } else { return '关闭'; } }); $show->created_at('添加时间'); $show->updated_at('更新时间'); return $show; } /** * Make a form builder. * * @return Form */ protected function form() { $form = new Form(new SmsRule); $form->display('ID'); $form->display('Created at'); $form->display('Updated at'); return $form; } /** * Make a form builder. * * @return Form */ protected function editForm() { $form = new Form(new SmsRule); $form->display('name', '规则名称')->setWidth(3); $form->display('alias', '别名')->setWidth(3); $form->radio('status', '状态')->options([0=>'关闭',1=>'开启']); $form->tools(function (Form\Tools $tools) { $tools->disableView(); $tools->disableDelete(); }); $form->saving(function (Form $form) { if ($form->status=='on') { $form->status=1; } elseif ($form->status=='off') { $form->status=0; } }); return $form; } protected function createForm() { $form = new Form(new SmsRule); $form->text('name', '规则名称')->rules([ 'required', 'unique:sms_rules', ])->setWidth(3)->setMustMark(); $form->text('alias', '别名')->rules([ 'required', 'unique:sms_rules', ])->setWidth(3)->setMustMark(); $form->radio('status', '状态')->options([0=>'关闭',1=>'开启'])->default(0); $form->saving(function (Form $form) { if ($form->status=='on') { $form->status=1; } elseif ($form->status=='off') { $form->status=0; } }); return $form; } /** * Store a newly created resource in storage. * * @return mixed */ public function store() { return $this->createForm()->store(); } /** * Update the specified resource in storage. * * @param int $id * * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response */ public function update($id) { return $this->editForm()->update($id); } }