Search code examples
phplaravellaravel-5laravel-7

$request->only() return empty array in laravel 7.9


I have a mess while laravel 5.4 to 7.9, I have read the follow document: https://laravel.com/docs/7.x/requests , but I am not clear in my case:

enter image description here

In laravel 5.4, it returns an array:

laravel 5.4

It's an emty array in laravel 7.9:

enter image description here

Thanks!


Solution

  • The problem you are describing is expected behaviour and was changed in between versions.

    Documentation from Laravel 5.4 Reference

    The only method returns all of the key / value pairs that you request, even if the key is not present on the incoming request. When the key is not present on the request, the value will be null.

    Documentation from Laravel 7.9 Reference

    The only method returns all of the key / value pairs that you request; however, it will not return key / value pairs that are not present on the request.