Search code examples
.htaccesslaravellaravel-5url-routinglaravel-5.3

how to change Url format of laravel paginate using Htaccess


How can I change Laravel page render url to this format.

http://exampel.com/articles?page=1

to

http://exampel.com/articles/page/1

Solution

  • You should implement pagination by yourself or use the included one

    Here is the docs

    Or the simple implementation

    you should specify your route, get result from database (or wherever you want), than slice the result array

    Route::get('articles/page/{id}', function ($id) {
        $articles = Article::all(); 
        $count = 15; //how many items per page
        //of course you should check if $id is not < 0 etc... 
        return view()->with([
            'articles' => array_slice($articles, $id*$count, $count)
       ])
    });