@newbie360 You could either create a form request and use prepareForValidation
https://laravel.com/docs/8.x/validation#preparing-input-for-validation or add a middleware similar to the TrimStrings middleware provided by Laravel. I would go with the former tho.
Feb 13, 2021
3
Level 24
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®ions[]=1®ions[]=2®ions[]=
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)) : [];
Please or to participate in this conversation.