问题
In laravel 4 when you try to render a view that does not exists in app\views or a view with undefined variables laravel will throw an exception or show error that helps with debug.
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.
I have installed filp/whoops:~1.0. but still recieve a blank page
class ProfileController extends Controller
{
public function index()
{
return view('indexx'); //this view does not really exist
}
}
The file indexx does not exist in my resources/views and i expect Laravel to throw an exception but am getting a blank page instead, why?
Also when i render a view that exists with some undefined variables i simply get a blank page
Example:
class ProfileController extends Controller {
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.
Also to note i change my laravel default view in config/views
'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
Also to mention that I install virtual box and vagrant on window 7
Could this be a bug or something? Please assist.
回答1:
Try to change permission on the storage folder:
chmod -R 0777 storage
It worked for me.
回答2:
I don't really know why this happened but its now working as required after i run
vagrant destroy
to destroy homestead VM
and then vagrant up
- to create the VM
The error messages has now showing up instead of blank page:

回答3:
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.
回答4:
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.
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.
回答5:
//lavarel 4 * Add this to 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
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);
}
来源:https://stackoverflow.com/questions/28877913/laravel-5-blade-shows-a-blank-page-when-there-is-error-instead-of-throwing-excep