如何在Laravel中正确定义home(/)路径?

How to properly define the home (/) route in Laravel?

假设我在 Laravel 5.3 中定义以下路线:

Route::resource('bands', 'BandController');

启动新的 Laravel 项目时出现的默认路由示例如下:

Route::get('/', function () {
    return view('welcome');
});

当没有调用控制器而不是 welcome 时,如何使 bands 路由成为默认路由?含义 /?

我确实阅读了文档 here 但没有找到任何内容。有吗?

将该块放在 laravel/app/routes.php 中而不是控制器 (4.x)

将该块放入 laravel/app/Http/routes.php 而不是控制器 (5.1)

将该块放入 laravel/app/routes/web.php 而不是控制器 (5.3)

Route::get('/', function()
{
    return view('welcome');
});

您可以将默认重定向到任何您想要的地方,即:

Route::get('/', function()
{
    return Redirect::to( '/bands');
    // OR: return Redirect::intended('/bands'); // if using authentication
});

正如@Patrick 提到的,您可以简单地重定向到 /bands 路线。但是,我必须警告您,重定向实际上会更改 Web 浏览器导航窗格中的 URL。我建议您只要求主路由使用 BandControllerindex 方法,如下所示:

Route::get('/', ['uses'=>'BandController@index']);