Dara Dev Dara Dev - 1 year ago 112
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')?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download