How to implement array type route in Laravel?

Here is the example which you want to implement.

Route::get('/{param?}', 'MyController@index')
    ->where('param', '(myroute|myroute2)');

By above route you can create following urls for the same controller function

www.site.com/
www.site.com/myroute
www.site.com/myroute2

Try this I think this will help you.


Route::get('/{myroute?}', function () {
    echo 'test';
})
    ->where('myroute', '(myroute|mysecondroute)');

This is an example. you define in your route a variable that can take the values you have in your where clase

That means that endpoints

api/myroute 
api/
api/mysecondroute

will access the same routing and elaborating the same controller

Tags:

Php

Laravel