繁体   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