I have a model selection code:

$list = $post->with(['actualBasicStats' => function($query){ //for filters }]) ->with(['actualExtStats' => function($query){ //for filters }]) ->whereIn('group_id', $groups->pluck('id')) ->paginate(); 

If you make a dd () result, you get this:

dd ()

But when I try to output data to the front, I use the blade to display the entire collection at once and build a paginator:

 <tbody> {{--{{dd($list)}}--}} @foreach($list as $post) <tr> <td>{{str_limit($post->text, 100)}}</td> <td>{{$post->actualBasicStats->likes or 0}}</td> <td>{{$post->actualBasicStats->reposts or 0}}</td> <td>{{$post->actualBasicStats->comments or 0}}</td> <td>{{$post->actualExtStats->reach_total or 0}} / {{$post->actualExtStats->reach_subscribers or 0}}</td> <td>{{$post->actualExtStats->to_group or 0}}</td> <td>{{$post->actualExtStats->join_group or 0}}</td> <td>{{$post->actualExtStats->links or 0}}</td> </tr> @endforeach </tbody> </table> {{$list->render()}} 

Output to the front

What am I doing wrong?

    2 answers 2

    Enter in the model not ->paginate() and ->paginate(15) and get 15 entries per page

    • If no value is specified, then the standard from model (15) is taken, but yes, I tried, it does not help. - Oleg Shakhov

    The problem was in the global scoop:

     static::addGlobalScope('first300', function (Builder $builder) { $builder->limit(300); }); 

    It overrides the limit for posts displayed on the page. Solved a problem:

     $list = $post->withoutGlobalScope('first300')->with(['actualBasicStats' => function($query){ //for filters }]) ->with(['actualExtStats' => function($query){ //for filters }]) ->whereIn('group_id', $groups->pluck('id')) ->paginate(20);