过滤搜索雄辩

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 filtering of category, job, Dept and city!

profiles : id, name, ......, job_id, location_id......
location : id, name, city_id
job : id, name, categorie_id
categorie : id, name
city : 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_location = \Input::has('ldept') ? \Input::get('llocation') : null;
        if(!isset($nom_catego) && !isset($nom_job)){
                   $query->where('categorie_id', '=' , $nom_catego)
                             ->where('id', '=', $nom_job);
        }
        if(!isset($nom_catego) && isset($nom_job)){
            $query->where('categorie_id', '=' , $nom_catego);
        }
        if(!isset($nom_job) && !isset($nom_location) && isset($nom_catego)){
                    $query->where('city_id', '=' , $nom_location)
                              ->where('id', '=' , $nom_catego);
        }
        if(isset($nom_job) && !isset($nom_location) && isset($nom_catego)){
            $query->where('city_id', '=' , $nom_location);
        }
    })->paginate(10);

NB : with this code I can get profiles by category and job, but I can not retrieve the profiles by city and location! Thank you for your help;

you can simply do it with query builder or with eloquent, note that whatever function available in query builder is available for eloquent query too, i have given my answer in query builder approach for simplicity,

  $results = DB::table('profiles')
        ->select(['profiles.*']);

    if($request->has('lcategorie')){
            $results->join('job','profiles.job_id','=','job.id');       
            $results->join('categorie','job.categorie_id','=','categorie.id');
            $results->where('categorie.id','=',$request->input('lcategorie'));

    }

    if($request->has('ljob')){
        if(!$request->has('lcategorie')){   //avoid repeat the join to same table multiple time
            $results->join('job','profiles.job_id','=','job.id');       
        }

        $results->where('job.id','=',$request->input('ljob'));
    }

    if($request->has('ldept')){
        $results->join('location','profiles.location_id','=','location.id');
        $results->join('city','location.city_id','=','city.id');
        $results->where('location.id','=',$request->input('llocation'));
    }

  $results = $results->get();

thank you Akram , it works, also added filtering by city as below :

    if($request->has('ldept')){
            $profiles->join('location','profiles.location_id','=','location.id');       
            $profiles->join('citys','location.city_id','=','citys.id');
            $profiles->where('citys.id','=',$request->input('ldept'));

    }

 if($request->has('llocation')){
        if(!$request->has('ldept')){   
            $profiles->join('location','profiles.location_id','=','location.id');       
        }

        $profiles->where('location.id','=',$request->input('llocation'));
    }