Laravel - Need a short consultation

Job ID: 35113397

Budget: €8 – €30 EUR

I have problem to making a search

I have 3 tables:
candidates:
id
name

teches: (technologies)
id
name

and pivot table
candidate_tech:
tech_id
candidate_id

Code:
public function index(Request $request)
{
$teches = Tech::latest()->get();



if ( null !== $request->input('search') ){
$technologies = $request->get('teches');
$email = $request->input('email');
$country = $request->input('country');
$fullName = $request->input('name');

$candidates= Candidate::where('email', 'LIKE', "%{$email}%")
->where('country', 'LIKE', "%{$country}%")
->where('first_name', 'LIKE', "%{$fullName}%")
->orWhere('last_name', 'LIKE', "%{$fullName}%")
->with('teches')->whereIn('id', $technologies)->get();
// ->whereHas('teches', function ($query) use($technologies) {
// $query->whereIn('id', $technologies);
// })->get();

return view('candidates.index')->with('candidates', $candidates)
->with('email', $email)
->with('country', $country)
->with('name', $fullName)
->with('teches', $teches);
} else {
$user_id = Auth::id();
$candidates = Candidate::latest()->paginate(10);

return view('candidates.index')->with('candidates', $candidates)->with('teches', $teches);
}

}

I need all the candidates with the searched technologies to be presented.
I need help
Related categories: PHP MySQL Laravel