WallyJ
6 months ago
1787
9
Laravel

Livewire Pagination, using mount()

Posted 6 months ago by WallyJ

I have followed the instructions in the docs here: https://laravel-livewire.com/docs/mount-method/

to get the results I want from my DB.

Livewire Controller

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Task;
use App\Contact;
use App\Contactnote;

class Contactshow extends Component
{

    public $contacts;
    public $tasktext;
    public $dealId;
    public $taskduedate;
    public $deal_id;

    public function mount($contacts)
    {
        $this->contacts = $contacts;
    }

    public function render()
    {
        return view('livewire.contactshow');
    }

}

View section of results:

<div class="col-md-12">
        <ul class="list-group">
            @foreach($this->contacts->contactnotes->sortByDesc('created_at') as $contactnote)
            <li class="list-group-item">
           {{$contactnote->created_at}} - {{$contactnote->contactnotetext}}
           </li>
            @endforeach
       </ul>
</div>

Results currently show correctly.

Now I want to paginate the results, but the paginate example in the docs:

https://laravel-livewire.com/docs/pagination/

does not use the mount() command in their example, so I am a bit confused. Not sure how to paginate at this point still using mount().

Please sign in or create an account to participate in this conversation.