xxxxxxxxxx
try {
// Your code that might cause the conflict goes here
} catch (\Illuminate\Database\QueryException $e) {
if ($e->getCode() === '23000') { // MySQL error code for a unique key constraint violation
// Handle the conflict
// You could redirect back with an error message or take any other necessary action.
}
// Optionally, you can still let other exceptions bubble up
throw $e;
}