I'm using Laravel 5.6
I have the following route that I want to allow only numeric values to be passed to id
:
Route::group(['middleware' => ['auth.jwt']], function () {
Route::get('endpoint/{id}/something', 'API\MyController@myMethod')
->where(['id' => '[0-9]+']);
});
public function myMethod($id)
But even when I pass a non-numeric value to id
, it's passing to MyController
@myMethod
, it's NOT preventing from executing the route.
Tried via the RouterServiceProvider.php
, without success too:
public function boot()
{
Route::pattern('id', '[0-9]+');
parent::boot();
}
Any ideas?
i don't know to prevent the user from entering a non-decimal value, but if i want to achieve the same result i will check first thing in myMethod()
for the $id
if isn't a decimal i will abort(404)
or redirect user back with some message.