Laravel: how to limit some route parameter to specific values?

Is it possible to make a route that takes a string parameter only for a specific string? Example:

 Route::get('{user_tipe}/event', 'admin\ EventC@index '); 

To route, I want to make the user_tipe parameter, allow only two lines, such as admin and author . Is it possible?

+5
source share
1 answer

You can do this using regex restrictions on your route:

 Route::get('{user_tipe}/event', 'admin\ EventC@index ')->where('user_tipe', 'admin|author'); 

admin|author - a simple regular expression that matches the string admin or author

+7
source

Source: https://habr.com/ru/post/1269173/


All Articles