farooq's avatar

Pagination not working after posting a value to controller and gets back

I have a page with post method . I already included pagination with that page . So it works perfectly , But after post , I'm sending the pagination to same page, but it shows only one page. When I click on next page it shows "Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message" . I added my controller here .

public function AssignVendor(Request $request){
$id = $request->input('id');
        $vendor_email = $request->input('vendorselect');
        $order_id = $request->input('order_id');
    // Some calculations here
    $users = Vendors::all();
        //$users = Vendors::paginate(5);
        $orders = Orders::orderBy('created_at', 'desc')->paginate(6);
        $success = "Updated Successfully";
        return \View::make('admin.Assign-Vendor')->with(compact('orders','users','success'));

    }
0 likes
4 replies
munazzil's avatar

You have to change this line return \View::make('admin.Assign-Vendor')->with(compact('orders','users','success')); as like below

         return view('admin.Assign-Vendor',compact('orders','users','success'));

and your view page use below

    {{$orders->Links()}}
1 like
munazzil's avatar

That error because of your routes check with below command in your CMD?and change your web.php file.else post here your files?

php artisan route:list
jlrdw's avatar

Your initial search is post but after that they are get requests.

Are you a appending in your parameters to pagination.

See Database Pagination in the documentation. Then go down to where it talks about appending.

    public function index()
    {
        if (!ChkAuth::chkRole('admin')) {  // Ignore I have custom RBAC
            return redirect('indexbl');   // Ignore I have custom RBAC
        }
        $page = Request::input('page', '1');
        $dogsearch = !empty(Request::input('psch')) ? Request::input('psch') : '';
        $aval = !empty(Request::input('aval')) ? Request::input('aval') : '';
        $dogsch = $dogsearch . "%";

       $query = Dog::where('dogname', 'like', $dogsch);
        if ($aval == "n") {
            $query->where('adopted', '=', 1);
        } else if ($aval == "y") {
            $query->where('adopted', '=', 0);
        }
        $dogs = $query->orderBy('lastedit', 'DESC')->paginate(5);

        $params = array('psch' => $dogsearch, 'aval' => $aval);
        $title = 'Admin';

return view('dog.index', compact('dogs', 'params'))->with('title', $title);

    }

The view

{{ $dogs->appends($params)->links() }}

But really all of this is covered in the documentation, and prior on the forum. To find just google:

site:laracasts.com pagination

or

site:laracasts.com pagination appending parameters

and

similar search terms

Above is a simplified example, I'd suggest you put the queries in scopes:

https://laravel.com/docs/5.8/eloquent#query-scopes

Also I'd highly suggest you take Jeffrey's "free" video training which is referenced right in the documentation.

Laracasts provides a free, thorough introduction to Laravel for newcomers to the framework. It's a great place to start your journey.

Page 1 of the docs, already a link there.

1 like

Please or to participate in this conversation.