【发布时间】:2015-08-04 11:05:13
【问题描述】:
我有一个文本输入:
{{ Form::text('first_name', $car->basicCustomer->first_name or NULL, ['class' => 'form-control', 'disabled']) }}
应该返回名字,但输入的值是 1。
die 和 dumped 返回时的关系:
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 等也是如此。
有什么想法吗?
编辑:幸运地修复了错误,需要使用并检查关系是否在另一个视图中不为空:
{{ Form::text('first_name', (!$car->basicCustomer ? NULL : $car->basicCustomer->first_name), ['class' => 'form-control', 'disabled']) }}
现在输出名称,谁能解释原因:
或为空
没有工作?
【问题讨论】:
-
or NULL 被解释为条件表达式。它返回真 (1) 或假 (0)。 “任何字符串” OR NULL 返回真 (1)。
标签: php laravel-4 relationship