Search code examples
laravelroutesslug

Laravel routing, slug with multiple possibilities


Been searching for a while and can't find an answer on if this is possible.

One URL I am trying to make. would be

/location/province-name/city/category

The province name only has a few options. Is there a way to set it up so something like this would work?

/{bc or ab or mn or etc}/{cityname}/{category}

does this make sense?


Solution

  • What you can do is use a pattern

    routes/web.php

    Route::pattern('province', '(bc|ab|mn|etc)');
    
    Route::get('/location/{province}/{city}/{category}', function ($province, $city, $category) {
        // TODO do something with your route
    });