php – 处理数据库无法连接laravel?

我想知道是否有一种方法可以在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');
    }

替换dd($e-> getMessage());使用您的自定义代码.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...