簡體   English   中英

Laravel關系為輸入值返回1

[英]Laravel relationship returning 1 for input value

我有文字輸入:

{{ Form::text('first_name',  $car->basicCustomer->first_name or NULL, ['class' => 'form-control', 'disabled']) }}

該名稱應返回名字,但輸入的值為1。

死亡和傾倒時的關系返回:

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...

即使調用last_name等,輸入中的值始終為1。

有什么想法嗎?

編輯:靠運氣修復了錯誤,需要使用它,以及是否要檢查關系是否在另一個視圖中不為空:

{{ Form::text('first_name', (!$car->basicCustomer ? NULL : $car->basicCustomer->first_name), ['class' => 'form-control', 'disabled']) }}

現在輸出名稱,任何人都可以解釋原因:

或NULL

沒有工作嗎?

or NULL被解釋為條件表達式。 並返回true(1)或false(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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM