Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

newbie360's avatar

Where the good place to write the logic of convert GET request query before controller method

a GET request with query string

http://localhost/users?regions[]=1&regions[]=1&regions[]=2&regions[]=

array:4 [▼
  0 => "1"
  1 => "1"
  2 => "2"
  3 => null
]

Controller

public function index(Request $request)
{
    $users = User::select(
        'id',
        'name',
    )
    ...
    ...
    ... many filter
    ...
    ...
    ->ofRegions($request->regions) // one of the filter
    ->paginate(20)->withQueryString();

    return view('users.index', compact('users'));
}

Model

public function scopeOfRegions($query, $regions)
{
    $regions = is_array($regions) ? array_unique(array_filter($regions)) : [];

    if ($regions) {
        return $query->whereHas('regions', function($q) use ($regions) {
            $q->whereIn('id', $regions);
        });
    }
}

my question is where is the good place for write the logic to covert the GET request variable

i think Validation is not good here, because is no landing page if fails

all i want is convert $request->regions with this ... before go into controller method

    $regions = is_array($regions) ? array_unique(array_filter($regions)) : [];
0 likes
3 replies

Please or to participate in this conversation.