Sometimes we need to grab only the request data which was sent through a form. Laravel’s $request->all() class returns all data – including that from the query string. This issue comes up often when using complex resource controllers over 2 models. Take the following example for updating pivot data on a Many-to-Many relationship via complex resource controller:

Copy to Clipboard

We start by extending Illuminate\Foundation\Http\FormRequest.

Copy to Clipboard

Now we inject it into our controller and can access the method.

Copy to Clipboard