簡體   English   中英

如何訪問laravel集合中的屬性

[英]How to access attributes in laravel collection

我有這個收藏

Collection {#611
  #items: array:1 [
    0 => Payeur {#605
      #guarded: array:1 [
        0 => "id"
      ]
      #attributes: array:11 [
        "id" => 1
        "prenom_payeur" => "aymen"
        "nom_payeur" => "larabi"
        "mobile_payeur" => "non"
        "telephone" => 230493212
        "observation" => "jeflolena"
        "adresse" => "jdjfnrll"
        "event_id" => 1
        "adherent_id" => 3
        "created_at" => "2019-12-22 14:57:43"
        "updated_at" => "2019-12-22 14:57:43"
      ]
    }
  ]
}

我想從這個集合中獲取nom_payeur屬性。 我以前做過很多次,但我不知道為什么會出現此錯誤:

(此集合實例上不存在屬性 [nom_payeur]。)

我試圖通過這樣做來獲取屬性: $payeur->nom_payeur , $payeur 是集合。 請幫忙。

try this hope its help
you have the collection and you try to access this property that is not possible beacuse in collection you can n't access element or attribute directly you have to use the array of index for this to access the poperty.

$payeur -> is collection this is incorrect way to access the property.

try this to access the attribute property.

$payeur[0]->nom_payeur 

暫無
暫無

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

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