Skip to content
Advertisement

how to apply pagination in this case using laravel 6

i got the annonces from a user authenticator, and i want to do pagination but i don’t know how.

UsersController.php

public function index()
    {
        $annonces = Auth::user()->annonces;
        $users = User::find(Auth::user()->id);
         return view('users.index')->with([
             'users'        => $users,
             'annonces'     => $annonces
         ]);
    }

Advertisement

Answer

public function index()
{
    $user = Auth::user();
    $annonces = $user->annonces()->paginate(5);

    return view('users.index', [
        'user' => $user,
        'annonces' => $annonces
    ]);
}
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement