php - Laravel 5.2 - Checking Authorization Abilities in a Multi Auth Application -
lets have following guards set , i'm logged in both jobseeker , recruiter. how can check authorization ability particular logged in user? default pass in current logged in user policy one?
the guards:
return [ 'guards' => [ 'jobseeker' => [ 'driver' => 'session', 'provider' => 'users', ], 'recruiter' => [ 'driver' => 'session', 'provider' => 'users', ], ], 'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => app\user::class, ], ], ] the policy:
protected $policies = [ post::class => postpolicy::class, ]; the action:
public function update($id) { $post = post::findorfail($id); if (gate::denies('update-post', $post)) { abort(403); } // update post... }
perhaps following:
public function update($id) { // user authorize $user = auth()->guard('recruiter')->user(); $post = post::findorfail($id); // option 1 if (gate::denies('update-post', [$user, $post])) { abort(403); } // option 2 if (gate::foruser($user)->denies('update-post', $post)) { abort(403); } // option 3 if ($user->cannot('update-post', $post)) { abort(403); } // update post... }
Comments
Post a Comment