A practical example that I found some time ago and saved because I knew it could be useful, sorry not to pass the code already with its variables, I answered here in the run :( but I believe you will not have problems in implementing.
home.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Paginação AJAX</title>
</head>
<body>
<h1>Usuários</h1>
<div class="users">
@include('users')
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
$(window).on('hashchange', function() {
if (window.location.hash) {
var page = window.location.hash.replace('#', '');
if (page == Number.NaN || page <= 0) {
return false;
} else {
getUsers(page);
}
}
});
$(document).ready(function() {
$(document).on('click', '.pagination a', function (e) {
getUsers($(this).attr('href').split('page=')[1]);
e.preventDefault();
});
});
function getUsers(page) {
$.ajax({
url : '?page=' + page,
dataType: 'json',
}).done(function (data) {
$('.users').html(data);
location.hash = page;
}).fail(function () {
alert('Falha ao carregar usuarios.');
});
}
</script>
</body>
</html>
Homecontroller.php
<?php
classHomeController extends Controller
{
public function main()
{
$users = DB::table('cache_users')->orderBy('timestampOld')->paginate(30);
if (Request::ajax()) {
return Response::json(View::make('users', array('users' => $users))->render());
}
return View::make('home', array('users' => $users));
}
}
users.blade.php
@foreach ($users as $user)
<article>
<h2>{{ $user->nome}}</h2>
{{ $user->telefone }}
</article>
@endforeach
{{ $users->links() }}
Useful link
How to Create an Ajax Pagination Using Laravel
I couldn’t adapt this code to my :x
– Wladi Veras
received the following reply Non-static method Illuminate Http Request::ajax() should not be called statically, assuming $this from incompatible context
– Wladi Veras
haha all right, I can do it this afternoon if I can wait or no one will answer :]
– Darlei Fernando Zillmer
A question before, you have a model for users??
– Darlei Fernando Zillmer
I do not use the models, I am passing the parameter directly through the controller
– Wladi Veras
Try now, it’s clearer I imagine
– Darlei Fernando Zillmer
Obs: the problem was the lack of before the Sponse and Request
– Wladi Veras
So you managed to solve?
– Darlei Fernando Zillmer