1

I try to filter my route like following :

Route::post('/vote/{bandId}', 'VoteController@vote')->where('bandId', '[0-9]+');

But it allows the following route :

http://localhost/vote/0

Which I do not want since I am fetching the resource from a query by filtering on the auto-increment field (which is greater than 0).

I tryied to type an advanced regex like I would do with preg_match() :

Route::post('/voter/{bandId}', 'VoteController@vote')->where('bandId', '[1-9][0-9]*');

Which let numbers between 1 and infinite.

Question

This last route does not works, how can I come with a complex regular expression to check the integrity of my wildcard before fetching the resource in my database ?

Anwar
  • 4,162
  • 4
  • 41
  • 62

1 Answers1

0

Try the following regex:

^[1-9]\d*$

Source: What is the regex for "Any positive integer, excluding 0"

Community
  • 1
  • 1
Jachinair
  • 272
  • 6
  • 15