Here is my model code trying to handle duplicate entries
:
$userData = ['name' => $name, 'email' => $email, 'password' => $password];
public function addUser($userData) {
try {
DB::table('users')->insert($userData);
} catch (QueryException $e) {
$errorCode = $e->errorInfo[1];
if($errorCode == 1062){
throw ('Duplicate Entry');
}
}
}
Calling controller code looks like: $userModel->addUser($userData);
Here I am not trying to print any response received from model
.
Getting error as:
What am I doing wrong? How to handle Exceptions correctly and what's the best practise of doing it?