Laravel - 返回子文件夹中的视图

时间:2018-02-13 14:41:03

标签: php laravel routes

我有以下几行:

-

但我的观点位于main / sub / index.blade.php

我试过

Route::get('/dashboard', function () {
    return view('main.index');
});

Route::get('/dashboard', function () {
        return view('main.sub.index');
    });

没有用。

1 个答案:

答案 0 :(得分:6)

将视图移至:

resources/views/main/sub/index.blade.php

然后这段代码就可以了:

Route::get('/dashboard', function () {
    return view('main.sub.index');
});

来自the docs

  

视图存储在resources/views目录中。由于此视图存储在resources/views/greeting.blade.php,我们可能会使用全局view帮助器返回它,如下所示:

return view('greeting', ['name' => 'James']);