Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is that possible to make route that accept string parameter only for specific string? Example :

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

That the route, I want to make the user_tipe param is only allow to two string like admin and author. Is that possible?

like image 540
Adi Sparta Avatar asked Jun 24 '17 05:06

Adi Sparta


1 Answers

You can do that using regular expression constraits on your route:

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

admin|author is a simple regular expression that will match either the string admin or author

UPDATE

Here you can find how to use the route param constraints when using Route::group

like image 143
Moppo Avatar answered Nov 03 '22 05:11

Moppo