DEV Community

Discussion on: Laravel Form Request Tips & Tricks.

dericlima profile image

Hey Mohammed, thanks for this article. It's very usefuil.
I'm having some issue to handle authorization dynamically in the form request, inside the authorize method.

I have a similar situation where I need to pass a second model in the can method inside the authorize function.

Since I'm using Lumen, I have defined both Gates and Policies but looks like the second model is not being binded in the Form Request.

So my question is: When you do $this->post to get the Post Model, from where this post property is coming from? Are you creating a post property inside the Form Request and binding the model from the Route there? I tried to get the model from the route using $this->route('my_model') without success. I might have missed something.....

Thanks for your time :)

secmohammed profile image
mohammed osama Author

Hello Deric, I appreciate that article is beneficial to you 😍
I haven't used Lumen, but there might be something missing, that to access the model instance inside your form request, your route has to be something like that
and then you can access it using $this->post or $this->route('post'), bear in mind that naming the route must be same as the name of the property you try to retrieve.

dericlima profile image

Hello Mohammed, I found out what the issue was. Actually it's a bug that's happening with Lumen only during tests.

When you try to access the model with $this->route('model') during tests, a array is being returned instead, which makes the code to break.

Everything is clear now. Thanks for your time.

If you are interested about the issue, more details here: