You would have to write your own paginator for that.
get pagination value from a session
making pagination with laravel is easy. however when you begin to modify somethings things get tangled. i want to get pagination value from a session not from post data via URL. well, i did not tried anything yet because i couldnt set up a roadmap. i know how to put a session and how to retrieve it but how i am gonna embed it into links() method?
Thats how my simple pagination works right now.
{{ $results->links() }}
EDIT: okey, i've found these two methods inside Illuminate\Pagination\AbstractPagination.php
/**
* Resolve the current page or return the default value.
*
* @param string $pageName
* @param int $default
* @return int
*/
public static function resolveCurrentPage($pageName = 'page', $default = 1)
{
if (isset(static::$currentPageResolver)) {
return call_user_func(static::$currentPageResolver, $pageName);
}
return $default;
}
/**
* Set the current page resolver callback.
*
* @param \Closure $resolver
* @return void
*/
public static function currentPageResolver(Closure $resolver)
{
static::$currentPageResolver = $resolver;
}
as far as undersood these two methods decides which page we are on(because we can see it in the Illuminate\Pagination\LengthAwarePaginator.phps __construct method). However i am having a hard time since idk about whats a Closure is. also there is no $resolver property or method in the page. Is it possible if he's(Taylor guy) saying write a resolver() method inside the page if you wanna put page number by yourself?
i did it laravel-fellas!!!
In order to this method to work you have to give pagination a new $pageName different than page. Luckly you can do that while calling your model like that
Model::paginate(10, ['*'], 'navi' ) //navi is the name of this paginator
and then go to the Illuminate/Pagination/PaginationserviceProvider.php and modify Paginator::currentPageResolver method like that.
Paginator::currentPageResolver(function ($pageName = 'page'){
$page = $this->app['request']->input($pageName);
//this if-else statements get $page variable from a session instead of url
if( $pageName == 'navi' ){
if( filter_var($page, FILTER_VALIDATE_INT) !== false ){
Session::put('currentPage', $page );
return (int) $page;
}
else {
return (int) Session::get('currentPage', 1);
}
}
if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
return (int) $page;
}
return 1;
});
This ifelse statements will get $page variable from url if it has been set and will put it into a session. if no information comes with Request, $page variable will be get from session.
Yes i am proud.
Please or to participate in this conversation.