Search code examples
phplaravellaravel-5laravel-routing

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?


Solution

  • 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