简体   繁体   English

无法访问受保护的财产

[英]Cannot access protected property

I'm learning Laravel's(4) Eloquent and I'm lost when it comes to accessing properties from the returned Eloquent object. 我正在学习Laravel的(4)Eloquent,当我从返回的Eloquent对象访问属性时迷路了。 This code doesn't work: 该代码不起作用:

public function show($email)
{
    $client = Client::where('email', $email)->get();
    echo var_dump($client->items);

}

The items property, which contains all the sub properties including email , is protected which means I can't access it by, say: $client->items->email . 包含所有子属性(包括emailitems属性受到保护,这意味着我无法通过以下方式访问它: $client->items->email So my question how do I access the properties of $client object? 所以我的问题是如何访问$client对象的属性?

get()用于基于查询获取所有记录,这意味着它将返回您可以循环访问的内容,例如,如果将var_dump($client->items)更改为var_dump($client[0]->items相反,如果您只需要一个记录,请使用first()而不是get()调用Eloquent模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM