我需要知道如何从数组中仅选择一个选项。我需要为两个图标制作一个@if
,但鉴于我收到的更多信息,我需要知道。
控制器:
$categoryID = \App\Category::pluck('id');
if($filter == 'all' || $filter == 'news')
{
$news = \App\News::with('user','category')->whereHas('user', function($query) {
$query->where('deleted_at', '=', null);
})->whereIn('category_id',$categoryID)->where(function($query1) use ($id) { $query1->where('public','=', 1)->orWhereHas('user.contact', function ($query2) use ($id) {
$query2->where('contacts.user_id', '=', $id);
})->orWhere('user_id','=',$id);
});
$temp['roleNews'] = $news->user->role;
视图中的代码:
{{$noticeboard_data['roleNews']}}
我收到的东西:
[
{"id":1,
"slug":"individuals",
"name":"Individuals",
"permissions":"",
"created_at":null,
"updated_at":null,
"pivot":{
"user_id":"542",
"role_id":"1"}
}
]
我只需要接收每个用户的role_id
,因为我将其用于类似这样的事情:
@if($noticeboard_data['roleNews'] == 1)
<i style="font-size: 15px" class="icon-user"></i>
@elseif($noticeboard_data['roleNews'] == 100)
<i style="font-size: 15px" class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
@endif
答案 0 :(得分:1)
也许我误解了这个问题,但是为什么不使用如下所示的关键路径呢?:
$noticeboard_data['roleNews']['pivot']['role_id']