I'm working on Laravel 5.1, and more specifically the Authorization package.
Before this package, I would do all my authorization checks in the FormRequest::authorize()
method, since this method was designed specifically for authorization checking.
I now want to use the native Authorization package in laravel, which includes Policy files, but I want to use them in the Request file.
This means, as far as I can see, that each form request file needs to be mapped to the policy file.
Surely this cannot be right? If I have 7 main methods in each controller, thats 7 mappings to a single policy file, 1 for each request file. If I then have 20 controllers, thats 140 mappings!
I know I can do that auth check in the controller, and just map the controller, but this seems to be poor implementation on Laravels behalf, otherwise why put the authorize()
method in the request?
Question
In an ideal world, I want to to my policy auth checking before reaching the controller - by doing it in the request. But I don't want to map out each of my request files to a policies.
Is there any way to retrieve the target controller from the request, so that I can just have one mapping - controller -> policy, and reference the controller from the request?