[Vuejs]-"explode() expects parameter 2 to be string, object given" [ Laravel, Vue ]

0👍

You’re executing your query here

$query = Employee::orderBy($request->column, $request->direction)
                            ->paginate($request->per_page);

Meaning you have a result here, not a query builder instance anymore.
You have to move paginate() after the search queries to make it work.

     public function index(Request $request)
     {
        $query = Employee::orderBy($request->column, $request->direction);

        if($request->search) {
            $query->where(function($query) use ($request) {
                $query->where('emp_name', 'like', '%' . $request->search . '%')
                ->orWhere('salary', 'like', '%' . $request->search . '%');
            });
        }

        $employees = $query->paginate($request->per_page); // execute the query

        return EmployeeResource::collection($employees);
     }

Leave a comment