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

SinghWithLaravel's avatar

I want to validate route parameter to be one of the two given values, How can i do it ?

route::post('InspectionChecks/List/{type}', 'InspectionChecksController@index');

In above route, i want type to be either ASSETor TRAILER. How can we achieve it without going to the controller ?

0 likes
6 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Use regex

route::post('InspectionChecks/List/{type}', 'InspectionChecksController@index')->where('type', '^(ASSET|TRAILER)$');
1 like
SinghWithLaravel's avatar

@sinnbeck I simply did it like this -

    Route::post('InspectionChecks/List/{type}', 'InspectionChecksController@index')->where('type',"ASSET|TRAILER");

What will regex will do here ?

Sinnbeck's avatar

Interesting. I would have assumed that the simple version of regex would have found a hit on ASSETTEST :) Oh well you learn something new everyday :)

The only difference between your version and mine is that I tell regex to make sure there is nothing before or after the work (start of line and end of line)

1 like

Please or to participate in this conversation.