Hey, what about a try catch blog like that:
...
try
{
// do your query here
}
//catch specific exception....
catch(QueryException $e)
{
// do sthg when the error occurs
}
Hey all, i try to make my first steps with laravel. Now i am at a point where i get angry :-) I try to use the eloquent save method... In my database i have a unique constraint over 3 columns. When i save a "really new" entry then everything is well. When i save an existing one (testing), it fails -> which is ok -> but i want to catch this error and display it in my application by my own. Instead of this i always get the "Whoops, looks like something went wrong." page. I don't want this page to be displayed.
How can i intercept the SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry error and display it by my own?
Thanks in advance and sorry for my bad english...
This happens because you are trying to catch a PDOException and PHP is throwing a QueryException.
try{
do_someting();
} catch(QueryException $e) {
echo "ERROR";
}
Just to be safe, you can catch any descendant of Exception instead:
try{
do_someting();
} catch(\Exception $e) {
echo "ERROR";
}
Please or to participate in this conversation.