Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement array type route in Laravel?

Tags:

php

laravel

I am trying to implement an array type route in Laravel 5.8.
Here's what I tried:

Route::get('/','/myroute', 'MyController@index');
Route::get(['/','/myroute'], 'MyController@index');
Route::get([('/','/myroute')], 'MyController@index');
Route::get('/' || '/myroute', 'MyController@index');  

Basically, what I'm trying to do is to create a route with an "OR" condition.
Let's say I want to access MyController index using mydomain.dev/ or mydomain.dev/myroute but I am getting a 404|Not Found.

Tried to read the Laravel documentation but I can't find something that points me to what I'm trying to do.

like image 332
fmsthird Avatar asked May 17 '19 08:05

fmsthird


Video Answer


1 Answers

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.

like image 156
Lakhwinder Singh Avatar answered Oct 23 '22 01:10

Lakhwinder Singh