0

I have a named route using a controller working perfectly. An issue arises when I chain a parameter validator, to ensure the passed question id is numeric.

Route::get('/question/{id}',
array('as' => 'question_route', 'uses' => 'QuestionsController@showQuestion'))
->where('id',[0-9+]);

Laravel throws this exception highlighting the ->where('id',[0-9+]);

Symfony \ Component \ Debug \ Exception \ FatalErrorException
syntax error, unexpected ']'

How can all 3 (as, uses, where) work together on a single route?

1 Answer 1

1

Are you sure the regex is [0-9+] not [0-9]+?

And there should be single quotes around it

Sign up to request clarification or add additional context in comments.

1 Comment

Silly mistake on my end, thanks for pointing it out Allen. I also want to add that it should be enclosed it single quotes too - I'll update your answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.