laravel/framework — pull request #1237 by miguelbgouveia (2013-05-08 10:19:41+00:00)
Title: Creation of the setBaseURL function for Ajax requests

When using pagination in an Ajax request is useful to be able to define the URL to be consider to build the paginate links. By default, in an Ajax request, it will be consider the Ajax URL to build the paginate links. This is a problem because generally in an Ajax response we do not rebuild the entry HTML page. To resolve this problem, we add to the Paginator class the setBaseURL function to indicate the URL to be consider. With this change we can, for example, proceed in the following way in the context of an Ajax request:

echo ‘

’;
$users = User:where(‘age’, ‘>’, ’18‘)->get();
foreach ($users as $user)
{
echo ‘
’.$user->name.‘
’;
}
$users->setBaseUrl(URL::route(‘users_list’));
echo ‘

’;
$users->links();

We can use the function $users->getEnvironment()->setBaseUrl() but we think the previous solution much more simple an elegant.