Perhaps break this down to individual steps, make sure each step works before putting all together.
Also look at whereHas in docs again for exact usage.
Sep 4, 2019
2
Level 1
Where retrun null if using wherehas after in laravel query
Where retrun null if using wherehas after in laravel query
This ->where('name', 'LIKE', '%'.$schoolname.'%') return nothing. Why?
public function listecoles(){
$schoolname = request()->query('query');
$location = request()->query('location');
$type = request()->query('type');
if($schoolname || $location || $type){
$schools = School::with('types')
->where('name', 'LIKE', '%'.$schoolname.'%')
->whereHas('ville', function ($query) use ($location) {
$query->where('name', $location);
})
->orWhereHas('quartier', function ($query) use ($location) {
$query->where('name', $location);
})
->paginate(10);
//return response()->json($schools);
}else{
$schools = School::paginate(6);
}
return view('frontend.liste-ecoles')
->with('statuts', Statut::all())
->with('types', Type::all())
->with('schools', $schools);
}
Level 75
Please or to participate in this conversation.