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.

Answers 1
  • 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'));
    
    0

    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