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
Laravel - return view in subfolder
提问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/views
directory. Since this view is stored atresources/views/greeting.blade.php
, we may return it using the globalview
helper like so:
视图存储在
resources/views
目录中。由于此视图存储在resources/views/greeting.blade.php
,我们可以使用全局view
助手返回它,如下所示:
return view('greeting', ['name' => 'James']);