Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aurorame's avatar

difference between request->data and request->input('data')

What the difference between this two: $request->data and $request->input('data'). Sometimes i can use $request->data but sometimes it return nothing, why?

0 likes
1 reply
Sinnbeck's avatar

->input() is a helper function, and it can do extra stuff like having a default as the second argument. It uses data_get so it can get nested values from array input for example. https://laravel.com/docs/9.x/helpers#method-data-get

Using ->property. If the request class has a property with the same name as the property you want, your ide will give an error. For example $request->json

Personally I only use ->input()

1 like

Please or to participate in this conversation.