我有一个文本输入:
{{ Form::text('first_name', $car->basicCustomer->first_name or NULL, ['class' => 'form-control', 'disabled']) }}
应该返回一个名字,但是输入的值却是1。
die和dumps的关系:
object(Customer)#805 (20) {
["connection":protected] "main_site"
["fillable":protected] array(8) {
[0] "title"
[1] "first_name"
[2] "last_name"
[3] "email"
[4] "telephone_number"
[5] "address"
[6] "post_code"
[7] "company_name"
}
["table":protected] NULL
["primaryKey":protected] "id"
["perPage":protected] 15
["incrementing"] true
["timestamps"] true
["attributes":protected] array(3) {
["first_name"] "John"
["last_name"] "Doe"
["id"] "19854"
}
["original":protected] array(3) {
["first_name"] "John"
["last_name"] "Doe"
["id"] "19854"
etc...
输入中的值总是1,即使调用last_name等
知道发生什么事了吗?
编辑:修正了运气的错误,需要使用和如果检查关系是否不是null在另一个视图:
{{ Form::text('first_name', (!$car->basicCustomer ? NULL : $car->basicCustomer->first_name), ['class' => 'form-control', 'disabled']) }}
现在输出名称,谁能解释为什么:
或空
不是工作?
将or NULL
解释为条件表达式。它返回真(1)或假(0)
'test' or null :
boolean true
'' or null :
boolean false
true or null :
boolean true
false or null :
boolean false
在您的情况下,您可以使用?:
操作符。
$string ?: null
是
的缩写$string ? $string : null