如果您想隐藏管理员用户并显示其余用户,您可以按照以下步骤操作。
在您的控制器中:-
public function index(Request $request)
{
$user = Auth::user();
if ($user->hasRole('admin')) {
$user = User::where('id', '!=', $user->id)->get();
} else {
$user = User::all();
}
return view('admin.users.index', compact('user'));
}
在您的刀片文件中:-
@foreach($user as $users)
@if(Auth::user()->hasRole('admin'))
<tr>
<td>{{$users->id}}</td>
<td>{{$users->name}}</td>
<td>{{$users->email}}</td>
<td>{{$users->password}}</td>
<td class="text-center">
<a href="{{ route('users.edit', $users->id)}}" class="btn btn-primary btn-sm">Edit</a>
<form action="{{ route('users.destroy', $users->id)}}" method="post" style="display: inline-block">
@csrf
@method('DELETE')
<button class="btn btn-danger btn-sm" type="submit">Delete</button>
</form>
</td>
</tr>
@endif
@endforeach