Laravel blade “old input or default variable”?

后端 未结 4 1950
执笔经年
执笔经年 2021-02-06 22:30

I want to show the old input in input value. If there isn\'t old input, than show other variable:

value=\"{{ old(\'salary_\' . $employee->id) or \'Default\' }         


        
4条回答
  •  情歌与酒
    2021-02-06 22:56

    or is a comparison operator in PHP, so your code is evaluating to true, or 1. What you want is a ternary if statement.

    As mentioned, or can be used in blade as shorthand for a ternary if statement.

    But you can (and should) just pass the default value as the second argument to the function, like so:

    value="{{ old('salary_' . $employee->id, 'Default') }}"
    

提交回复
热议问题