1 year ago

Pass multiple arguments to a policy method that don't require models

Posted 1 year ago by Julien44

Hi guys, How can i pass multiple arguments to policy authorization method that don't require models ? I tried to call the policy method in my FormRequest's authorize method like that :

    public function authorize()
        return $this->user()->can('create', Signalement::class, Request::get('place_id'));

And here is my Policy method :

    public function create(User $user, $placeId)
        return $user->accounts->pluck('place_id')->contains($place_id);

It throw me this error : "Too few arguments to function App\Policies\SignalementPolicy::create(), 1 passed and exactly 2 expected"

I know i could use the Request::get('place_id') directly in the create method, but i would prefer to pass is as an argument if possible Thanks !

Please sign in or create an account to participate in this conversation.