syntax error, unexpected 'else' (T_ELSE), expecting function (T_FUNCTION) or const (T_CONST) [closed]
Your code is a mess. Your inconsistent indentation is not helping you.
public function index(Request $request){
$title = $request->get('title');
$type = $request->get('type');
$category = $request->get('category_id');
$province = $request->get('province');
$brand= $request->get('brand_id');
$address = $request->get('address');
$race = $request->get('race');
$dealer_experience = $request->get('dealer_experience');
if($title||$type||$category||$address||$brand||$race ||$dealer_experience) {
$candidates = Profile::query();
if ($title) {
$candidates = $candidates->where('title','LIKE','%'.$title.'%');
}
if ($category) {
$candidates = $candidates->where('category_id',$category);
}
if ($brand) {
$candidates = $candidates->where('brand_id',$brand);
}
if ($type) {
$candidates = $candidates->where('type',$type);
}
if ($address) {
$candidates = $candidates->where('address','LIKE','%'.$address.'%');
}
if ($race ) {
$race = $race ->where('race',$race);
}
if ($dealer_experience) {
$dealer_experience = $dealer_experience->where('dealer_experience',$dealer_experience);
}
}
$candidates = $candidates->where('profile_status',1)->paginate(5);
return view('profile.allcandidates',compact('candidates'));
}
else
{
$candidates= Profile::latest()->where('profile_status',1)->paginate(2);
return view('profile.allcandidates',compact('candidates'));
}
}
Leverage the functionality of your IDE to clean up your indentation automatically. Once you do so, it's pretty easy to spot the additional closing bracket.