문제

with credit to the user called Kindari @ irc room #laravel in freenode , also credit goes to user iampseudo and Debolaz.

with following laravel route code,

Route::bind('key_pairs', function($s) {
// some logic to transform string to associative array
$arr = explode("/",$s);
$arr2 = array();
if(count($arr)%2 == 0)
{
    for($i=0;$i<count($arr);$i+=2)
    {
        $arr2[$arr[$i]] = $arr[$i+1];
    }
}
return $arr2;   
});

Route::get('foo/{key_pairs}', function($key_pairs) {
var_dump($key_pairs);
})->where('key_pairs', '.*'); 

now we can get /foo/page/1 for Laravel to read as /foo?page=1 , but former is more prettier than latter.

now what is needed here is for Laravel's pagination instance to read /page/1 rather than ?page=1 , so pretty pagination urls will work smoothly.

Does anyone know now to do this , without altering the base code ?

if we can have something like Users::paginate(5)->page($page) or any other functionality if already exists (which i am unable to find) , that is great.

cheers

도움이 되었습니까?

해결책

Okay problem solved , now pretty pagination urls for Laravel is working and here is the solution.

i added the getByPage method into the relevant model class posted in the following link (Credit goes to him)

and called $this->user->getByPage($page, $limit); in the Routes ,

There we have Pretty pagination URLs !

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top