I implemented several out-guards in the Laravel 5.4 project (one of administrators and another for regular users). So far, this has worked successfully, and both administrators and users can log in. Now I'm trying to implement a Policy class that works for both Auth guards. This is because I have certain models that I want all administrators to edit, and only users who own the model to be able to edit. Therefore, I defined the policy using this method.
App \ Policies \ ModelPolicy
public function update(User $user, Model $model)
{
if ($user->id === $model->user_id) {
return true;
}
if (Auth::guard('admin')->check()) {
return true;
}
return false;
}
Then in any controller method that I have for my model:
App \ Http \ Controllers \ ModelController
public function update(Model $model)
{
$this->authorize('update', $model);
}
, . , , ( ). , Policy -, , Auth::check() . , ( ), .
, , , -admin:
public function update(Model $model)
{
if (!Auth::guard('admin')->check()) {
$this->authorize('update', $model);
}
}
- , , . , , .
?