Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'order clause'

I’m trying to make pagination after sorting in my Laravel project , so I did this method, it sorts my data but when I want to see next paginate table it shows me this error

SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'order clause'
SELECT * FROM `customers` ORDER BY `` DESC limit 3 OFFSET 3

My method

 public function Sortfilter(Request $request)
    {
        $active = Customer::where('active','=','1')->count();
        $inactive = Customer::where('active','=','0')->count();
        $customer = Customer::query();

        $customer = Customer::orderBy($request->filter,'desc')->paginate(3);
        return view('customers.index', compact('customer','inactive','active'));


    }

is there a method to save the $request->filter data when I click on next button

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

EDIT

when i sort my data the URL change like that : http://127.0.0.1:8000/sortCustomer?filter=phone&_token=9xw0q9MKa5ABZc4CwkLaPqf5ko4BhJ4ZaEk0VKYY

and when i click to the pagination button the URL be like that :

http://127.0.0.1:8000/sortCustomer?page=2

>Solution :

In Laravel there is the option to append query string values to pagination links.

Using this your code could look like this:

public function Sortfilter(Request $request)
{
    $active = Customer::where('active','=','1')->count();
    $inactive = Customer::where('active','=','0')->count();
    $customer = Customer::query();

    $customer = Customer::orderBy($request->filter,'desc')->paginate(3)->withQueryString();
    return view('customers.index', compact('customer','inactive','active'));
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading