I am trying to build a search on my website (using the laravel 5.2). I need to search multiple tables at once. Basically I need to display the information of profile by filtring of category, job, Dept and city!
profiles : id, name, ......, job_id, city_id......
city : id, name, dept_id
job: id, name, categorie_id
categorie: id, name
dept: id, name
in below code :
$profils = \App\Profils::whereHas('jobs', function($query){ $nom_catego = \Input::has('lcategorie') ? \Input::get('lcategorie') : null; $nom_job = \Input::has('ljob') ? \Input::get('ljob') : null; $nom_dept = \Input::has('ldept') ? \Input::get('ldept') : null;
if(!empty($nom_catego) && !empty($nom_job)){
$query->where('categorie_id', '=' , $nom_catego)
->where('id', '=', $nom_job);
}
if(!empty($nom_catego) && empty($nom_job)){
$query->where('categorie_id', '=' , $nom_catego);
}
if(!empty($nom_job) && !empty($nom_dept) && empty($nom_catego)){
$query->where('city_id', '=' , $nom_dept)
->where('id', '=' , $nom_catego);
}
if(empty($nom_job) && !empty($nom_dept) && empty($nom_catego)){
$query->where('city_id', '=' , $nom_dept);
}
})->paginate(10);
Thanks
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community