-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I define a Gate and the code never gets called, always denies authorization #19306
Comments
Gate::define('create-post', function ($user, $project) { You didn't put a semicolon after |
You can pass as many arguments you would like to a policy method. You must use an array to do this: PostPolicy
{
public function create($user, $project)
{
return $project->owner_id == $user->id;
}
} public function store(Post $post)
{
$project = Project::find(1);
$this->authorize('create', [$post, $project]);
} The first argument will be used to locate the correct policy, the others will be added to the arguments of the function call. |
do you have a policy defined for |
Closing for lack of activity from the original author. Thanks everyone who tried to help, but I don't think it's an issue with the core since we got no complains on this. |
my guess is he has a Policy defined for |
@browner12 I am having this issue on L5.8, |
Just had the same issue because I forgot to add the |
Description:
In my Laravel 5.4 application users can create Projects and then Posts inside those projects.
I'm trying to prevent users from creating or editing posts inside a project they don't have access to.
To do this I implemented a Gate as explained here: https://laravel.com/docs/5.4/authorization#gates
Steps To Reproduce:
The gate checks if a user is the owner of the project.
On the PostController I call Gate::denies passing the project as an argument
The problem is the code I defined for the gate never gets called. Instead it always returns false and goes to the 403 error.
However, the code does get called if I don't pass the project as an argument but that makes it useless.
I also want to add that in this case I cannot use a Policy because the create method only takes one argument ($user) and if I try to pass the $project it fails the same way it does with the Gate.
Is this a bug? Is there another, better way to implement this funcionality? Thanks.
The text was updated successfully, but these errors were encountered: