try {
$user->save();
return redirect()->back()->with('status', 'Saved!');
} catch(IlluminateDatabaseQueryException $e){
$errorCode = $e->errorInfo[1];
if($errorCode == '1062'){
return back()->with('error', 'Duplicated data');
}
else{
return back()->with('error', $e->getMessage());
}
}