Dara Dev Dara Dev - 3 months ago 10
PHP Question

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

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


Example:


  • 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')?

Answer

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.