Don't know if this will help but have a look.
https://laraget.com/blog/how-to-create-an-ajax-pagination-using-laravel
I'm trying to have a section on my contact view that shows contact notes, 4 per page, in a box that goes through pages without refreshing the page. This may require AJAX, but I'm just trying to get the pagination to show at the moment.
Here's my code. Since I'm using the "with" to eager load the "contactnotes", I don't know where to put the pagination function.
Contacts Controller:
//Look up contact chosen by URL
$contacts = Contact::with(['contactnotes', 'deals.tasks'])->find($id);
// Check for correct user
if(auth()->user()->id !== $contacts->user_id){
return redirect('/contacts')->with('error', 'That Is Not Your Contact');
}
// Update Last Seen Field for viewed contact
Contact::where('id', $id)
->update(['contactlastseen' => \Carbon\Carbon::now()]);
return view('contacts.show', ['contact' => $contacts, 'contactnotes' => $contacts->contactnotes, 'deals' => $contacts->deals]);
View:
<div class="col-md-12">
<ul class="list-group">
@foreach($contactnotes->sortByDesc('created_at') as $contactnote)
<li class="list-group-item">
{{$contactnote->created_at->diffForHumans()}} - {{$contactnote->contactnotetext}}
</li>
@endforeach
</ul>
</div>
I may ultimately go with a static box with a scroll bar and add infinite scroll capabilities to it, so it doesn't take up much space on the screen and would also not require a page refresh.
Ideas? Thanks!
Please or to participate in this conversation.