【发布时间】:2016-09-22 09:41:07
【问题描述】:
考虑以下场景。
- 有2个用户注册了系统。
- 如果用户 1 已登录并尝试更新用户 2 的配置文件。不应该被允许。
我已经尝试过使用 Request 类。
use App\Http\Requests\Request;
use Auth;
use App\User;
class ProfileRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
$routeUser = $this->route('userId');
if($routeUser->id == Auth::user()->id){
return true;
}
else{
abort(403);
}
}
}
问题:它显示包含所有信息的表单。它仅在尝试更新信息时阻止用户。如何阻止用户,使他/她甚至无法查看带有数据的表单??
【问题讨论】:
标签: php laravel-5.2 laravel-authorization