1

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

1 Answer 1

4

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 !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.