[Vuejs]-Fetch data via search from two Table with where condition in Laravel ,vuejs

0👍

Controller method looks like overenginired.
You should do something like this.

$employees = Employee::with('Company')
    ->when($request->filled('q'), function ($query) use ($request) {
        return $query
           ->where('name', 'like', "%$request->q%")
           ->whereHas('Company', function ($query)  use ($request) {
                return $query->where('name', 'like', "%$request->q%");
            });
    })->paginate(5);

put your field name.

Leave a comment