Skip to content

Commit

Permalink
fix filter
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzodibenede committed Nov 15, 2024
1 parent fc29d42 commit f327600
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/Http/Controllers/PokemonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public function index(Request $request): \Illuminate\Contracts\View\View|\Illumi
{
$query = Pokemon::query();

if (!empty($request->name)) {
if (isset($request->name) && !empty($request->name)) {
$query->where('name', 'LIKE', '%' . $request->name . '%');
}

if (!empty($request->type1) && !empty($request->type2)) {
if (isset($request->type1) && !empty($request->type1) && isset($request->type2) && !empty($request->type2)) {
if ($request->type2 == "None") {
$query->where(function ($q) use ($request) {
$q->where('type1_id', $request->type1)
Expand All @@ -34,13 +34,13 @@ public function index(Request $request): \Illuminate\Contracts\View\View|\Illumi
});
}
} else {
if (!empty($request->type1filter)) {
if (isset($request->type1) && !empty($request->type1)) {
$query->where(function ($q) use ($request) {
$q->where('type1_id', $request->type1)
->orWhere('type2_id', $request->type1);
});
}
if (!empty($request->type2)) {
if (isset($request->type2) && !empty($request->type2)) {
if ($request->type2 == "None") {
$query->where('type2_id', null);
} else {
Expand Down

0 comments on commit f327600

Please sign in to comment.