我想知道是否有一种方法可以在laravel无法连接到数据库时显示自定义视图?我试过谷歌搜索答案,但它确实没有显示任何有用的东西.
我目前得到:
Whoops, looks like something went wrong.
2/2
QueryException in Connection.PHP line 770:
sqlSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (sql: select * from `users` where `users`.`id` = 1 limit 1)
谢谢.
解决方法:
在你的app / Exceptions / Handler.PHP中,转到render方法.您可以添加以下异常检查来处理查询和pdo异常
if ($e instanceof \Illuminate\Database\QueryException) {
dd($e->getMessage());
//return response()->view('custom_view');
} elseif ($e instanceof \PDOException) {
dd($e->getMessage());
//return response()->view('custom_view');
}