Laravel-admin 实现 form 表单是增加或者修改的三种方法,应用情景:1、新增或者修改 form 展示的表单不同;2、新增或者保存前后回调进行其他的操作
1、 use IlluminateSupportFacadesRoute; Route::currentRouteName () == ' 路由名称.edit' 2、 isset(request()->route()->parameters['路由名']) ? '修改' : '添加'; (域名/admin/路由名) 3、return $content ->header($this->title) ->description('新增') ->body($this->form()); return $content ->header($this->title) ->description('详情') ->body($this->form(false)->edit($id)); protected function form($status = true) { if($status) $form->text('account_number', '经销商账号')->required()->rules(function($form){ return $form->model()->id ? 'required' : 'required|unique:account_managements,account_number'; }); else $form->text('account_number', '经销商账号')->readOnly(); }