Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude Laravel-specific values from request

I want to run json_encode($request->all()) after a form is submitted, however the returned array is "polluted" with _method and _token values.

Is there any neat way to exclude the framework-specific fields from the generated json?

like image 811
Alex Lomia Avatar asked Nov 29 '22 23:11

Alex Lomia


2 Answers

$request->only('username', 'password');

or

$request->except('_method', '_token');

Source: https://laravel.com/api/5.3/Illuminate/Http/Request.html#method_only

like image 112
Rinon Avatar answered Dec 19 '22 01:12

Rinon


Yes, the Request class provides just that

$request->except('_method', '_token')
like image 38
alepeino Avatar answered Dec 19 '22 01:12

alepeino