1

I am using laravel 5.1 pagination. But its not working. I guess the problem is accessing query string parameter.

routes.php

Route::get('blogs', 'front\FrontController@blog');

Controller

public function blog(Request $request)
{
    print_r($request->fullUrl());
    die;
    $blogs=Blog::with('User')->where('flag','!=','0')->paginate(2);
    return view('front.pages.blog_list',['blogs'=>$blogs]);
}

For url http://localhost/myproject/blogs?page=2

Result : http://localhost/myproject/blogs?blogs. Where it should be ?page=2 instead of ?blogs. I have also noticed that query string parameters are not also working in others page. Any idea? Thanks in advance.

Md. Mahmud Hasan
  • 842
  • 5
  • 20

2 Answers2

1

use ->appends(\Input::except('page'))

return view('front.pages.blog_list',[ 'blogs'=>$blogs->appends(\Input::except('page')) ]);

Ravisha Hesh
  • 1,397
  • 11
  • 16
  • Thanks @Ravisha Hesh. But It's not working. I dont know why I cant access query string :( parameters... – Md. Mahmud Hasan Jun 12 '16 at 04:19
  • did you see your params when you add `dd($request->all());` into your method? – Ravisha Hesh Jun 12 '16 at 04:22
  • Yes @Ravisha Hesh. It does not show page. just Array ( [blogs] => ) . – Md. Mahmud Hasan Jun 12 '16 at 04:33
  • leave `dd()` as I mentioned on previous comment and go to http://localhost/myproject/blogs?page=2 manually by clicking on this link – Ravisha Hesh Jun 12 '16 at 04:38
  • I tried manually and it does not showing page parameter @Ravisha Hesh – Md. Mahmud Hasan Jun 12 '16 at 04:49
  • So how to do appends from vuejs/ajax. Like I want to add product id in query params and I want to paginate number of comments that one product have. – Bangash May 02 '20 at 00:22
  • 1
    You can use `appends($request->all())` in laravel to include additional params in pagination, pagination object contains links to next and prev pages, use those for navigation – Ravisha Hesh May 02 '20 at 03:43
  • http://127.0.0.1:8000/api/comments?cpId=3&page=1 this is my url, and it's not working, If I remove cpid from query string it works well. I am return custom array not query result. – Bangash May 02 '20 at 17:30
  • got it, my mistake, It working perfectly thank you. changes i made is $comments->appends(['cpId' => $pid])->links(); – Bangash May 02 '20 at 17:41
1

The reason was .htaccess file.

Md. Mahmud Hasan
  • 842
  • 5
  • 20