public function show(Request $request)
{
$annonces = Annonce::when($request->term, function ($query, $term) {
return $query->where('title', 'like', "%{$term}%");
})->when($request->categorie, function ($query, $categorie) {
return $query->where('categorie', 'like', "%{$categorie}%");
})->when($request->price && in_array($request->price, ['more-expensive', 'less-expensive']), function ($query) use ($request) {
return $query->orderBy('price', $request->price == 'less-expensive' ? 'asc' : 'desc');
}, function ($query) {
return $query->orderByDesc('id');
})->paginate(15);
return view('welcome', compact('annonces'));
}