Laravel ErrorException试图获取非对象的属性

时间:2017-05-28 22:36:12

标签: php laravel

我使用此代码

收到此错误
<JsonIgnore> Public btnUpdate As New Button
<JsonIgnore> Public btnReset As New Button
<JsonIgnore> Public btnClear As New Button

我知道这个时间<?php foreach(App\Campaign::all() as $campaign) { ?> <?php $category_id = $campaign->category->id; $emailTemplates = App\EmailTemplate::where('category_id', $category_id); $lastEmailNumber = $emailTemplates->latest()->first()->number; $currentEmailNumber = $campaign->emails->last()->number; ?> <?php for ($i = $currentEmailNumber + 1; $i < $lastEmailNumber; $i++) { ?> <?php $pass = $emailTemplates->where("number", $i)->first()->password; ?> <?php } ?> <?php } ?> $currentEmailNumber = 0 问题来自第9行的变量$lastEmailNumber = 14。如果不使用$ i,我使用1到14之间的任何数字都不会出现任何错误。例如:

$i

但是,如果我只显示<?php $pass = $emailTemplates->where("number", 10)->first()->password; ?> ,则没有正确显示所有句子。 也许这是演员问题。

1 个答案:

答案 0 :(得分:0)

解决:

改变了这个:

<?php $pass = $emailTemplates->where("number", $i)->first()->password; ?>

为此:

<?php $pass = App\EmailTemplate::where('category_id', $category_id)->where("number", $i)->first()->password; ?>

我不知道为什么会这样。