我想向用户显示他们的级别分别为git checkout 86b403574c90f16b77da4bef8d67a71471ad7f77
和admin
。
operator
但是我得到这个错误
为foreach()提供的参数无效(视图:C:\ xampp \ htdocs \ new \ shopping \ resources \ views \ Admin \ levelAdmin \ create.blade.php)
答案 0 :(得分:0)
我不知道您是否正在使用(\App\User::whereLevel('admin')->get() || \App\User::whereLevel('operator')->get()
,因为其中一个查询可能为空,或者是否要获取level
匹配admin
或operator
的用户
对于第一种情况,请尝试以下操作:
@if(!empty(\App\User::whereLevel('admin')->get()))
@foreach(\App\User::whereLevel('admin')->get() as $user)
//
@endforeach
@else
@foreach(\App\User::whereLevel('operator')->get() as $user)
//
@endforeach
@endif
如果要获得level
与operator
或admin
匹配的用户,则应使用somenthin修改查询,如下所示:
@foreach(\App\User::where('level', 'admin')->orWhere('level', 'operator')->get() as $user)
//
@endforeach