[英]Laravel : How to use eloquent ORM to find information of NOT authenticated user?
So I have this function to get the info of a user who is currently logged in. 所以我有这个功能来获取当前登录用户的信息。
$users = User::get();
$loginuser = $users->find(Auth::user()->id);
How do I use Laravel's eloquent ORM to get other users and put it in an array variable? 我如何使用Laravel雄辩的ORM来获取其他用户并将其放入数组变量中? Maybe something like
也许是这样的
$otherusers = $users->find(not(Auth::user()->id));
Of course, it will not work but you get what I mean. 当然,它不起作用,但你明白我的意思。 Bonus points for improvement of the first 2 lines above~!
改善前2行以上的奖励积分〜! Thank you!
谢谢!
You may try this to get all the users other than the logged in user: 您可以尝试此操作以获取登录用户以外的所有用户:
$otherusers = User::where('id', '!=', Auth::user()->id)->get();
If you use Auth::user()
then you'll get only the currently logged in user. 如果您使用
Auth::user()
那么您将只获得当前登录的用户。 So for example: 例如:
// Logged In user, You can directly use
// Auth::user()->id or any property, no
// need keep it in a variable for that
$loggedInUser = Auth::user(); // Returns a single Model
// Other users (Returns a collection of user models)
// Check if a user is logged in before you use Auth::user()->id
$otherusers = User::where('id', '!=', Auth::user()->id)->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.