Skip to content
Advertisement

Try catch for laravel is not working for duplicate entry

I am using below code in laravel controller. And getting duplicate error for username but I need to handle it by try-catch. This code is not working.

JavaScript

I am getting this error, which I need to handle by try and catch

JavaScript

Thanks for your help.

Advertisement

Answer

You need to make Exception as global,

  1. Either by using.

    JavaScript

and then use

JavaScript
  1. Or by using

    JavaScript

Instead of this

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement