Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to catch duplicate entry to database in laravel

//I'm assuming you use MySQL, it's probably different for other systems

//Okay first, the error code for duplicate entry is 1062. And here's how you retrieve the error code from the exception:
try{
  User::add_user($user_details);
}
catch (IlluminateDatabaseQueryException $e){
    $errorCode = $e->errorInfo[1];
    if($errorCode == 1062){
        // houston, we have a duplicate entry problem
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: php carbon 
Php :: laravel field types from database field type 
Php :: global variable in laravel 
Php :: laravel @env 
Php :: get the selected value of dropdown php 
Php :: php backend generator 
Php :: insert into php myqsl 
Php :: define multiple variables in one line php 
Php :: queue jobs in laravel 
Php :: error handling in laravel 
Php :: php page sends cookie to visitor 
Php :: merge strings in php 
Php :: laravel 8 
Php :: php check empty variable 
Php :: phpexcel 
Php :: php array form 
Php :: Use the DebugBar like an array where keys are the collector names 
Php :: laravel - access file from storage path - alternative to symlink 
Php :: movies -inurl:(htm|html|php|pls|txt) intitle:index.of “last modified” (mp4|wma|aac|avi) 
Php :: php integer to js integer 
Php :: traduction website with i18n 
Php :: cpt change link 
Php :: RouteSubscriber disallow user routes 
Php :: eventon php code 
Php :: form data to php Class 
Php :: Adding Conditional Classes to Menu Items 
Php :: how to create php message 00 
Php :: add selected to dropdpown item laravel 
Php :: send emails with runtime configurations in laravelk 
Php :: laravel simple 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =