14

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?

Moppo
  • 18,797
  • 5
  • 65
  • 64
Adi Sparta
  • 525
  • 2
  • 7
  • 23

1 Answers1

32

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

facricci
  • 23
  • 1
  • 5
Moppo
  • 18,797
  • 5
  • 65
  • 64
  • 1
    nice, the regular expression for routes is the best way for that – RAUSHAN KUMAR Jun 24 '17 at 06:18
  • 1
    Thanks @moppo. I tried same approach on the `Route::group(['prefix' => '/{lang}'], function(){ //Routes for en and fr goes here. })->where('lang', 'en|fr');` but i got this error `Call to a member function where() on null`. Please, any heads up to solve my worry? – FONGOH MARTIN May 16 '18 at 17:14