Failed to connect DB processing in laravel?

I was wondering if there is a way to show a custom view when laravel cannot connect to the database? I tried to find the answer to this question, but in fact it does not show anything useful.

I am currently getting:

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)

Thank.

+4
source share
1 answer

In app/Exceptions/Handler.phpselect method render. You can add the following exception check to handle exceptions queryandpdo

    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');
    }

Replace dd($e->getMessage());with your own code.

+2
source

Source: https://habr.com/ru/post/1665505/


All Articles