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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48769328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:22:51  来源:igfitidea点击:

Laravel - return view in subfolder

phplaravelroutes

提问by uppermost

I have got following lines:

我有以下几行:

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

But my view is located in main/sub/index.blade.php

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

I tried

我试过

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

also

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

didnt work.

没用。

回答by Alexey Mezenin

Move the view to:

将视图移至:

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

Then this code will work:

然后此代码将起作用:

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

From the docs:

文档

Views are stored in the resources/viewsdirectory. Since this view is stored at resources/views/greeting.blade.php, we may return it using the global viewhelper like so:

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

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