F
F
Froks2017-04-09 11:24:02
Laravel
Froks, 2017-04-09 11:24:02

laravel pagination?

Hello. I warn you in advance, I'm a newbie, so sorry if this is a dumb question.
There is a table with Posts (the title, text and author's id are stored) and a Followers table (the user's id and the id of the user to which he is subscribed are stored)
How can I get only those posts whose authors are the users we are subscribed to and so that pagination works?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D3lphi, 2017-04-09
@Froks

Post::select()->join('subscribers', 'posts.author_id', 'subscribers.author_id')->where('subscribers.user_id', 1)->paginate(15);

Instead of 15 - the number of elements on the page. Instead of 1 - id of the current user. Well, in select it would be nice to list the columns you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question