[英]How to use IN or Nesting of queires in Eloquent ORM of Laravel 4
[英]Laravel : How to use eloquent ORM to find information of NOT authenticated user?
所以我有這個功能來獲取當前登錄用戶的信息。
$users = User::get();
$loginuser = $users->find(Auth::user()->id);
我如何使用Laravel雄辯的ORM來獲取其他用戶並將其放入數組變量中? 也許是這樣的
$otherusers = $users->find(not(Auth::user()->id));
當然,它不起作用,但你明白我的意思。 改善前2行以上的獎勵積分〜! 謝謝!
您可以嘗試此操作以獲取登錄用戶以外的所有用戶:
$otherusers = User::where('id', '!=', Auth::user()->id)->get();
如果您使用Auth::user()
那么您將只獲得當前登錄的用戶。 例如:
// 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.