get all users except the followings users in overtrue laravel-follow

Created at 20-Aug-2021 , By samar

get all users except the followings users in overtrue laravel-follow

Through many examples, we will learn how to resolve the "get all users except the followings users in overtrue laravel-follow".

You can get all the users except the followings users in overtrue laravel-follow package. It is one of the most common case in which you have to show the users list on your page to whom you did not follow yet.
  • Get all users list except the followings users in overtrue laravel-follow package

    $user = Auth::user();
    $users = User::select('id', 'name', 'image')->whereNotIn('id', $user->followings->pluck('id'))->where('id', '<>', $user->id)->take(4)->inRandomOrder()->get();
    return view('user')->with(compact('users'));
    

    This code snippet will help you to get the all users who you did not follow yet. It will get ids from the user's table using the followings() method and avoid the user records using the whereNotIn() method and also the record of the logged-in user and return to view file.

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.