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

修改管理员状态


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

php
public function updateStatus()
{
	$manager = $this->request->Model;
	// 不能禁用自己
	if($this->request->UserModel->id === $manager->id){
	ApiException('不能禁用自己');
	}
	$manager->status = $this->request->param('status');
	return showSuccess($manager->save());
}

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

php
// 验证规则
protected $rule = [
    ...
	'id|管理员id'=>'require|integer|>:0|isExist:Manager',
    'status'=>'require|integer|in:0,1'
    ...
];

protected $scene = [
	...
	'updateStatus'=>['id','status'],
];

路由 router/admin.php

php
Route::post('manager/:id/update_status','admin.Manager/updateStatus');