我的路线定义如下:
Route::get('/buyer_home', function(){
$senders = \App\Message::where(['to' => \Auth::guard('web_buyer')->user()->username])->distinct()->get(['from']);
$sellers = array();
foreach ($senders as $sender) {
$sellers[] = \App\Seller::where('email', $sender->from)->get();
}
return view('buyer.home', compact('sellers', 'senders'));
});
我处于这种情况,我需要在视图中访问sellers
表/模型的列/属性,以建立这样的条件:@if(sender->from == seller->email)
。但我得到了
当我尝试访问此集合实例上不存在属性[email]。
email
循环中每个sellers
结果的@foreach
属性时出现错误消息。我的目的是将sellers
的列表传递给视图,并且只有那些拥有与email
$sender->from
匹配的电子邮件的卖家。<div class="list-group">
@foreach($sellers as $seller)
<a href="#" class="list-group-item">From: {{ $seller->email }}</a>
@endforeach
</div>
。我该如何解决这个问题?
修改
这是我的视图代码的片段,其中引发了错误:
class Program
{
static void Main(string[] args)
{
var storageAccount = new StorageAccount();
//Configure Storage Account and get the reference of a newly created table
try
{
var cloudTableReference = storageAccount.CloudTableInstance;
if (cloudTableReference != null)
{
Console.WriteLine("Table {0} created successfully using SAS token", cloudTableReference.Name);
}
else
{
Console.WriteLine("There is an error in new table creation");
}
}
catch (Exception ex)
{
Console.WriteLine("Error in configuring Azure Storage Account - {0}", ex.Message);
}
}
}
答案 0 :(得分:0)
我看到了问题。
$sellers
是一个集合数组。您应该使用whereIn
$emails = array_map(function($s) {
return $s->from;
}), $senders);
$sellers = \App\Seller::whereIn('email', $emails)->get();
另一种方法是在你的视图中替换:
<a href="#" class="list-group-item">From: {{ $seller[0]->email }}</a>