Support the ongoing development of Laravel.io →
Requests Eloquent Views

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

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

visualo visualo Joined 24 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.