Load with pagination
Hi,
Let's say, I want to load 15 posts for a user :
$user = User::first();
$user->load(['posts' => function($q){
$q->paginate();
}]) ;
I get array of posts, not page
why not simple $user->posts()->paginate() ?
Maybe this is what you want
$user->load(['posts' => function ($query) use (&$posts) {
$posts = $query->paginate();
}]);
dd($posts);
Write this in controller function
$users = User::paginate(15);
return view('user', compact('users'));
View
<table>
<tbody>
@foreach($users as $key => $user)
<tr>
<td><center> {{$user->name}} </center></td>
<td><center> {{$user->post}} </center></td>
</tr>
@endforeach
</tbody>
</table>
And this will create links for pages
<div class="text-center">
{!! $users->links(); !!}
</div>
Please or to participate in this conversation.