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

kazehaya's avatar

Input old edit form displays 1 using or with blade

Hey all,

Im trying to find a clean and easy way for displaying the old input when i edit a form. If there is no input old i want to show the stored field data form the database.

The way i want it to work is like this:

old('firstname') or $user->customer->firstname

However this is showing me the integer 1 as value.

I know i can use the old if else shortcode like this ? : however if prefer using the convenient short-cut of blade.

Thanks in advance for helping!

0 likes
4 replies
pmall's avatar

Use value="{ { (old('firstname')) ? old('firstname') : '' } }" (obviously no spaces between { { and } }, but render problem on the forum)

Because or expects a variable and not a function.

1 like
kazehaya's avatar

@pmall Thanks for stopping by, what you suggested does not return my default value from the database.

I got it working like this:

strlen(old('firstname')) ? old('firstname') : $user->customer->firstname

However i think this is much more convenient. Show the old input if it exist, else show me the first name from the database.

old('firstname') or $user->customer->firstname

However this does return 1 as default, and it should display the first name instead.

pmall's avatar
pmall
Best Answer
Level 56

@kazehaya yes, and I told you the reason why it does not work is the blade's or directive expect a variable and you pass a function.

I completely forgot : I think you can use old('firstname', $user->customer->firstname). The second parameter is the default value.

2 likes
kazehaya's avatar

@pmall old('firstname', $user->customer->firstname) worked like a charm :) Thanks a lot for helping me!!

Please or to participate in this conversation.