:)
I have implemented a search functionality for users who want to browse job postings, it looks like this:
https://i.stack.imgur.com/wGcW6.png
The code for it looks like this:
public function index(Request $request)
{
if ($word = $request->get('s')) {
$postsQuery = $postsQuery
->where('titel', 'like', "%{$word}%")
->where('isActive', 1)
->where('is_Canceled', 0)
->orWhere('id', '=', $word);
}
if ($location = $request->get('standort') and $request->get('standort') != 'alle') {
$postsQuery = $postsQuery->where('Standort', $location);
}
if ($dep = $request->get('abteilung') and $request->get('abteilung') != 'alle') {
$postsQuery = $postsQuery->where('abteilung_name', $dep);
}
$posts = $postsQuery->orderBy('titel')->get();
if ($posts->count() == 0) {
return view('posts.overview', ['posts' => $posts, 'standorts' => $standorts, 'abteilungs' => $abteilungs])
->withErrors(['error' => 'Es wurde kein Treffer gefunden, versuchen Sie es mit anderen Suchparametern']);
}
return view('posts.overview', ['posts' => $posts, 'standorts' => $standorts, 'abteilungs' => $abteilungs]);
}
My issue is that only one parameter gets searched for. So when a user enters a search term "IT" + a location (Standort) or a department (Abteilung) only the search term is searched for.
I tried countless different things for 2 hours but I just cant get it to work. If you have any tipps let me know!
EDIT: when I leave out the orWhere('id', '=', $word) it works, but I have to leave it in. But I cant change it to normal where() because then it returns no matches.