Exclude Laravel-specific values from request
Asked Answered
P

2

6

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?

Pushbike answered 29/7, 2016 at 17:57 Comment(0)
A
21
$request->only('username', 'password');

or

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

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

Artemisia answered 29/7, 2016 at 18:3 Comment(1)
Something to note: both this answer and the one below convert the request to an array which may not be desirable.Taurine
U
5

Yes, the Request class provides just that

$request->except('_method', '_token')
Unshaped answered 29/7, 2016 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.