Laravel 5.2 视图设置为 public 文件夹
Laravel 5.2 view set to public folder
我正在尝试让我的路由访问 public 文件夹,因为我正在尝试使用 laravel 作为 api 和 angular 作为前端。我已经从
的配置文件夹中更改了视图文件
'paths' => [
realpath(base_path('resources/views')),
],
至
'paths' => [
realpath(base_path('public/views')),
],
在我的 public 文件夹中,我创建了一个 views 文件夹并放置了一个名为 test.html 的文件
现在
Route::get('/',function(){
return view('test.html');
});
显示错误
in FileViewFinder.php line 137
at FileViewFinder->findInPaths('test.html', array('C:\xampp\htdocs\customer_portal\public\views')) in FileViewFinder.php line 79
at FileViewFinder->find('test.html') in Factory.php line 165
at Factory->make('test.html', array(), array()) in helpers.php line 779
at view('test.html') in routes.php line 36
at RouteServiceProvider->{closure}()
你知道我做错了什么吗?
问题是你在 html 文件上使用 return 视图('test.html')!这是错误的,视图应该用于 php blade 模板。相反 return 文件的内容(在我的项目 FilesController 中的代码 I copy-paste 下方):
use Response;
...
public function downloadFile(Request $request)
{
...
return Response::download(path_to_your_file, download_file_name);
}
并在 routes.php
文件中而不是 Route::get('/',function(){...
中输入:
Route::get('/', 'FilesController@downloadFile');
我正在尝试让我的路由访问 public 文件夹,因为我正在尝试使用 laravel 作为 api 和 angular 作为前端。我已经从
的配置文件夹中更改了视图文件 'paths' => [
realpath(base_path('resources/views')),
],
至
'paths' => [
realpath(base_path('public/views')),
],
在我的 public 文件夹中,我创建了一个 views 文件夹并放置了一个名为 test.html 的文件 现在
Route::get('/',function(){
return view('test.html');
});
显示错误
in FileViewFinder.php line 137
at FileViewFinder->findInPaths('test.html', array('C:\xampp\htdocs\customer_portal\public\views')) in FileViewFinder.php line 79
at FileViewFinder->find('test.html') in Factory.php line 165
at Factory->make('test.html', array(), array()) in helpers.php line 779
at view('test.html') in routes.php line 36
at RouteServiceProvider->{closure}()
你知道我做错了什么吗?
问题是你在 html 文件上使用 return 视图('test.html')!这是错误的,视图应该用于 php blade 模板。相反 return 文件的内容(在我的项目 FilesController 中的代码 I copy-paste 下方):
use Response;
...
public function downloadFile(Request $request)
{
...
return Response::download(path_to_your_file, download_file_name);
}
并在 routes.php
文件中而不是 Route::get('/',function(){...
中输入:
Route::get('/', 'FilesController@downloadFile');