Just like having a Vue component that gets props passed to it. You do not paginate inside of that component but from the blade file or Livewire component which is passing that contact data to it. Confusion is that you are using singular component example for the plural purposed component.
Feb 28, 2020
9
Level 3
Livewire Pagination, using mount()
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().
Level 122
Yes. You cannot pagination a child.
If you have $contact as a single model then
$notes= $contact->contactnotes()->paginate();
Pass this $notes to the view and iterate on it
1 like
Please or to participate in this conversation.