novatoolpermissions icon indicating copy to clipboard operation
novatoolpermissions copied to clipboard

Possible wrong signature of Gate::any()

Open leo-unglaub opened this issue 5 years ago • 1 comments

Hey, i am looking thru your documentation and i found this here:

public function view($user, $post)
{
    return Gate::any(['viewBlog', 'manageBlog'], $user, $post);
}

But i cannot find an implementation of Gate::any with that signature (with three params). Are you sure this is intended? Or did you mean:

public function view($user, $post)
{
    return Gate::any(['viewBlog', 'manageBlog'], [$user, $post]);
}

Thanks and greetings Leo

leo-unglaub avatar Oct 07 '19 12:10 leo-unglaub

@leo-unglaub , you're correct. Provided example as well as default policies implementations are misleading. On the other hand $user is passed to the callback anyway, so providing $post would be sufficient in this case (but still not required):

public function view($user, $post)
{
    return Gate::any(['viewBlog', 'manageBlog'], $post);
}

https://laravel.com/docs/7.x/authorization#writing-gates

Gates always receive a user instance as their first argument, and may optionally receive additional arguments such as a relevant Eloquent model

andrzejkupczyk avatar Jul 24 '20 14:07 andrzejkupczyk