S
S
Shamil Khairulaev2021-06-11 16:28:38
Laravel
Shamil Khairulaev, 2021-06-11 16:28:38

How to make pagination for posts that belongsTo(User::class)?

I know that in order to paginate all articles, you need to write
$paginator = Post::simplePaginate($perPage);
A how it is done with the posts of a specific user that I want to display.

Here's what my code looks like without pagination:

$author_id = $request->input('author_id');

        if ($author_id !== null) {
            $author = User::find($author_id);
            return view('blog.posts.index', compact('author'));
        }

What needs to be written to promote his articles? Sorry if this is a dumb question, I just started learning laravel.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2021-06-12
@jazzus

$posts = $user->posts()
    ->paginatge(10);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question