Laravel 5刀片在出现错误而不是抛出异常时显示空白页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28877913/
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 5 blade shows a blank page when there is error instead of throwing exception
提问by Emeka Mbah
In laravel 4 when you try to render a view that does not exists in app\viewsor a view with undefined variables laravel will throw an exception or show error that helps with debug.
在 laravel 4 中,当您尝试渲染app\views中不存在的视图或具有未定义变量的视图时,laravel 将抛出异常或显示有助于调试的错误。
I have a fresh installation of laravel 5.0.13 and am having a tough time troubleshooting a blade template that shows a blank page when i render a view that does not exists instead or a template with undefined variables instead of throwing an exception or error which will clue me in when debug.
我有一个全新的 Laravel 5.0.13 安装,当我呈现一个不存在的视图或带有未定义变量的模板而不是抛出异常或错误时,我很难对显示空白页的刀片模板进行故障排除调试时提示我。
I have installed filp/whoops:~1.0. but still recieve a blank page
我已经安装了 filp/whoops:~1.0. 但仍然收到空白页
class ProfileController extends Controller
{
public function index()
{
return view('indexx'); //this view does not really exist
}
}
The file indexxdoes not exist in my resources/viewsand i expect Laravel to throw an exception but am getting a blank page instead, why?
文件indexx不存在于我的资源/视图中,我希望 Laravel 抛出异常但得到一个空白页,为什么?
Also when i render a view that exists with some undefined variables i simply get a blank page
此外,当我渲染一个存在一些未定义变量的视图时,我只会得到一个空白页
Example:
例子:
class ProfileController extends Controller {
类 ProfileController 扩展控制器 {
public function index()
{
return view('index'); //this view exists
}
}
}
The content of resources/views/index
资源/视图/索引的内容
{!! $this_variable_was_not_passed_an_I_expect_error !!}
As you can see in the view file above the variable does not exist by laravel will simply show a blank page instead of throwing an exception or some debug error.
正如您在上面的视图文件中看到的,laravel 不存在变量只会显示一个空白页面,而不是抛出异常或一些调试错误。
Also to note i change my laravel default view in config/views
另请注意,我在 config/views 中更改了 laravel 默认视图
'paths' => [
//realpath(base_path('resources/views'))
realpath(base_path('resources/themes/default'))
],
And laravel was able to render views from resources/themes/default as long as there is no error in the template however, if any error was encountered such ar undefined variable a laravel displays a blank page instead of showing error message
只要模板中没有错误,laravel 就能够从资源/主题/默认呈现视图,但是,如果遇到任何错误,例如未定义的变量,laravel 会显示一个空白页面而不是显示错误消息
Also to mention that I install virtual box and vagrant on window 7
还要提一下,我在窗口 7 上安装了 virtual box 和 vagrant
Could this be a bug or something? Please assist.
这可能是一个错误还是什么?请协助。
采纳答案by Emeka Mbah
I don't really know why this happened but its now working as required after i run
我真的不知道为什么会发生这种情况,但是在我运行后它现在可以按要求工作了
vagrant destroy
to destroy homestead VM
vagrant destroy
摧毁宅基地虚拟机
and then vagrant up
- to create the VM
然后vagrant up
- 创建虚拟机
The error messages has now showing up instead of blank page:
错误消息现在显示而不是空白页:
回答by Marcio Sartini
Try to change permission on the storage folder:
尝试更改存储文件夹的权限:
chmod -R 0777 storage
It worked for me.
它对我有用。
回答by Sven van den Boogaart
An alternative solution which helped me, is running
一个帮助我的替代解决方案正在运行
composer install
I deployed with git which auto ignores some files. running composer install fixed it for me.
我用 git 部署,它自动忽略了一些文件。运行 composer install 为我修复了它。
回答by Dietmar
I got the same problem but here comes the reason and the solution: The logfiles in storage/logs needs to be owned/writable by the webserver user. Otherwise L5 gives you a blank page.
我遇到了同样的问题,但原因和解决方案来了:存储/日志中的日志文件需要由网络服务器用户拥有/可写。否则 L5 会给你一个空白页。
I run "php artisan ..." always as root. If an exception was thrown and Laravel creates a new logfile, then it's owned by root. On my Debian i run in the project root folder:
chown www-data.root * -R
to solve this problem.
我总是以 root 身份运行“php artisan ...”。如果抛出异常并且 Laravel 创建了一个新的日志文件,那么它归 root 所有。在我的 Debian 上,我在项目根文件夹中运行:
chown www-data.root * -R
来解决这个问题。
回答by m0z4rt
//lavarel 4 * Add this to app/start/gobal.php
// lavarel 4 * 将此添加到 app/start/gobal.php
App::error(function(Exception $e, $code) {
$runner = new \Whoops\Run;
$inspect = new \Whoops\Exception\Inspector($e);
$handler = new \Whoops\Handler\PrettyPageHandler;
$handler->setRun($run);
$handler->setInspector($insp);
$handler->setException($e);
return $handler->handle($e);
});
//lavarel 5 * Add this to app/Exceptions/Handler.php
// lavarel 5 * 将此添加到 app/Exceptions/Handler.php
public function render($request, Exception $exception)
{
..........
$runner = new \Whoops\Run;
$inspect = new \Whoops\Exception\Inspector($e);
$handler = new \Whoops\Handler\PrettyPageHandler;
$handler->setRun($run);
$handler->setInspector($insp);
$handler->setException($e);
$handler->handle($e);
......
return parent::render($request, $e);
}