ollie_123's avatar

Pagination - No Links Showing

Evening All

I'm stuck on something thats so simple but just baffling me. I'm trying to paginate some records but the pagination links don't appear. I've done a dd($completeOrders) and i can see the orders & pages detail etc but just no links in the view.

Please could one of you kind folk advise where i might be going wrong or what i'm missing.

//Controller 
 $completeOrders = Order::where('stage', 'complete')->orderBy('completed_at', 'desc')->paginate(8);
//View
@forelse($completeOrders as $complete)
	//Table
@endforelse
{{ $completeOrders->links() }}

Thank you in advance.

0 likes
8 replies
MichalOravec's avatar
@forelse($completeOrders as $complete)
    // table 

    {{ $completeOrders->links() }}
@empty
    <p>No orders</p>
@endforelse

And of course if you don't have more that 8 orders in your database, the pagination links won't show.

ollie_123's avatar

Hey @michaloravec

Thanks for your response.

I've tried both in & out the forelse loop but still no joy in showing the links.. Also tried just a @foreach but no joy either.

 {{ $completeOrders->links() }}
@empty
  <tr>
   	<td colspan="11" class="strong">No orders found.</td>
  </tr>
@endforelse
MichalOravec's avatar

Move it outside of foreach, because you propably show it in the table.

<table>
    @if ($completeOrders->isNotEmpty())
        foreach ($completeOrders as $complete)
            // tr
        @endforeach
    @else
        <tr>
            <td colspan="11" class="strong">No orders found.</td>
        </tr>
    @endif
</table>

{{ $completeOrders->links() }}
ollie_123's avatar

@michaloravec I've tried it inside and outside of the loop.

I also tried using the ```@if statement you recommended & still no joy.

Do you think the naming might be throwing it off having complete in both the variables at the start of the foreach?

MichalOravec's avatar
Level 75

If you put to the url ?page=2, ?page=3 etc do you get different result in the table?

ollie_123's avatar

@michaloravec I think you've just answered my question.

Because i have the orders on tabs Pending | Complete | Void i think the tabs are throwing it out.

I'll have to split onto separate pages. Thank you for your help. Much appreciated.

1 like

Please or to participate in this conversation.