Dara Dev Dara Dev - 6 months ago 29
PHP Question

Laravel request->input('') or old('') always return 1 in blade

I want to get the url data into my input value.


  • the url is http://example.com/user?username=example

  • and my html input code is as below

  • <input value="{{ request()->input('username') or old('username') }}">

  • but the result always return "1" and not "example"

It seems like the "or" blade helper acts as conditional operator.

How can I get the username value from url into that input and still get the default value as old('username')?


Try with

request()->input('username', old(('username'))

It will retrieve username as an input if it exists or default to the old value. You can also give a default value to the old helper.