简体   繁体   English

如何访问laravel集合中的属性

[英]How to access attributes in laravel collection

I have this 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"
      ]
    }
  ]
}

and I want to get the nom_payeur attributes from this collection.我想从这个集合中获取nom_payeur属性。 I did this many times before and I don't know why I get this error:我以前做过很多次,但我不知道为什么会出现此错误:

(Property [nom_payeur] does not exist on this collection instance.) (此集合实例上不存在属性 [nom_payeur]。)

I'm trying to get the attributes by doing this: $payeur->nom_payeur , $payeur is the collection.我试图通过这样做来获取属性: $payeur->nom_payeur , $payeur 是集合。 Please help.请帮忙。

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