Only view policy method not being authorized correctly? #1929
Unanswered
renejpeter
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Put /**
* Determine whether the user can show the model.
*
* @param \App\Models\User $user
* @param \App\Models\User $model
* @return \Illuminate\Auth\Access\Response|bool
*/
public function show(User $user, User $model)
{
return $user->can('view-user');
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have this weird issue where my controller's index, create and update methods are authorized correctly via the policy, but my show method doesn't seem to be using the Policy. When viewing the requests in Telescope, switching to the Gate tab, I can see the proper permissions being validated for all routes except the show route. It just denies the initial check.
UsersController Index Route
UsersController Show Route
The user is authenticated via Sanctum for each of the requests, so it's not an authentication issue. I can't figure out why only the show method isn't authorizing. Below are the steps I used to set everything up.
Seeded some permissions
Seeded some roles and assigned permissions to them
Seeded some users and assigned a role to one
Checked the database after seeding and everything checks out. Users are created, the staff user has the required roles, and the roles have the required permissions assigned.
Created some resource controllers via artisan for each model
Created some policies for each controller via artisan
Added a constructor to each controller to tell it to use the policies
In the Policy, update the methods to use the custom permissions created earlier
Added resource routes to
routes/api.php
Added the policies to AuthServiceProvider
I haven't changed anything in the
permission.php
config file.Everything seemed to have worked except the show method on the resource controllers.
Have I forgotten to do something somewhere? Did I mess up somewhere? I just can't seem to figure out why only that method doesn't authorize correctly. Keep in mind, this happens for each resource controller, not just the UsersController. The show method on each controller repeats this behaviour.
Beta Was this translation helpful? Give feedback.
All reactions