Laravel刀片“旧输入或默认变量"? [英] Laravel blade "old input or default variable"?
问题描述
我想在输入值中显示旧输入.如果没有旧的输入,则显示其他变量:
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' }}"
但是当没有旧输入时,它会给我1而不是默认值!
But when there is no old input, it gives me 1 instead of the default value!
我认为问题与串联有关,但我不知道如何解决!!
I think the problem has something to do with the concatenation, but I don't know how to fix it!?
推荐答案
or
是PHP中的比较运算符,因此您的代码求值为true
或1. c2>语句.
or
is a comparison operator in PHP, so your code is evaluating to true
, or 1. What you want is a ternary if
statement.
如前所述,or
可以在刀片中用作三元if语句的简写.
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') }}"
这篇关于Laravel刀片“旧输入或默认变量"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!