how to catch query exception in laravel 8

Solutions on MaxInterview for how to catch query exception in laravel 8 by the best coders in the world

showing results for - "how to catch query exception in laravel 8"
Mirko
23 Jul 2020
1try { 
2  $results = \DB::connection("example")
3    ->select(\DB::raw("SELECT * FROM unknown_table"))
4    ->first(); 
5    // Closures include ->first(), ->get(), ->pluck(), etc.
6} catch(\Illuminate\Database\QueryException $ex){ 
7  dd($ex->getMessage()); 
8  // Note any method of class PDOException can be called on $ex.
9}
10