Skip to content
关注公众号,获取新课通知

增加权限


控制器 app/controller/admin/Rule.php

php
public function save(Request $request)
{
    $res = $this->M->save($request->param());
    return showSuccess($res);
}

验证器 app/validate/admin/Rule.php

// 验证规则

php
protected $rule = [
	'rule_id'=>'require|integer|isExist:Rule,false',
	'status'=>'require|in:0,1',
	'name'=>'require',
	'condition'=>'require',
	'menu'=>'require|in:0,1',
	'order'=>'require|integer',
	'method'=>'in:GET,POST,PUT,DELETE',
];

protected $scene = [
    ...
    'save'=>['rule_id','status','name','menu','order','method'],
];

// app/validate/BaseValidate
// 根据id判断是否存在,存在将实例加入request
protected function isExist($value, $rule, $data='', $field='',$title = '记录'){
	$arr = explode(',',$rule);
	if (!$value) return true;
	$Model = '\\app\\model\\'.$arr[0];
	$M = $Model::find($value);
	if (!$M) {
		return '该'.$title.'不存在';
	}
	// 将当前实例挂在到Request上
	if ($arr[1] !== 'false') request()->Model = $M;
	return true;
}

路由 router/admin.php

php
Route::post('rule','admin.Rule/save');