获取所有用户,除了laravel口外的当前登录用户 [英] Get all the users except current logged in user in laravel eloquent
本文介绍了获取所有用户,除了laravel口外的当前登录用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做
User::all();
从用户表中获取所有用户.我想选择除当前登录用户之外的所有用户.我该怎么办?像
to get all the users from users table. I want to select all the users except current logged in user. How should I do that? something like,
User::where('id','!=',$currentUser->id)->get();
提前谢谢!
推荐答案
您可以使用auth()->id()
获取当前用户的ID.然后将其传递给查询:
You can get the current user's id with auth()->id()
. Then pass that to the query:
$users = User::where('id', '!=', auth()->id())->get();
这篇关于获取所有用户,除了laravel口外的当前登录用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文