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.

我试着读Laravel documentation,但是我找不到任何东西来指引我要做的事情.

推荐答案

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

试试这个,我想这对你有帮助.

Laravel相关问答推荐

未将Laravel Blade属性传递给组件或类

Laravel:通过数据透视表数据限制多对多Eager 加载

Laravel 语法 GroupBy 获取列到数组

工厂多对多数据透视表属性

API GET 请求得到与数据库记录不同的结果

在 Laravel 包中的路由上使用显式或隐式模型绑定

laravel Eloquent 模型更新事件未触发

Lumen 中的自定义 404 页面

eloquent的搜索/自定义属性的位置

如何在包中安排 Artisan 命令?

向 Docker 上的 Artisan 推荐方式

Laravel 4 - 如何将所有字段的所有验证错误消息作为 JSON struct 返回?

Laravel Eloquent 模型中的字段

Laravel 字符串验证以允许空字符串

是否可以将路由参数传递给 Laravel 中的控制器构造函数?

laravel 队列 - 同步驱动程序如何工作?它是在单独的进程/线程还是主执行线程中执行?

Laravel 4:将什么作为参数传递给 Url 类?

Laravel 表:只能有一个自动列,并且必须定义为键

同一模型上的 Laravel 父/子关系

Distinct values with pluck