How to create a database error page in laravel
How to create a database error page in laravel
Here, we are going to create a custom database error page in laravel.
Step 1: Let's go to the file with the path App/Exceptions/Handler.php and move to render function and paste the below code.
public function render($request, Exception $exception)
{
if ($exception instanceof \Illuminate\Database\QueryException) {
// dd($exception->getMessage());
return response()->view('errors.db');
} elseif ($exception instanceof \PDOException) {
dd($exception->getMessage());
//return response()->view('custom_view');
}
else{
return parent::render($request, $exception);
}
}
Step 2: Now create a folder named error and file named as db.blade.php, let's open the db.blade.php file and paste the below code.
@extends('layouts.app')
@section('content')
<section class="section">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 text-center">
<div class="card">
<div class="card-body py-5">
<h1 class="main-heading text-danger">Connection Refused</h1>
<hr>
<h4>Please Bare with us. Under Maintenance</h4>
</div>
</div>
</div>
</div>
</div>
</section>
@endsection
Now you are done with displaying database connection error page in laravel.
Thanks for reading.