Solution:
I’m guessing you’re referring to the Query Builder’s update
method (which returns the updated count) and not the Eloquent one (which returns a Boolean value). If that’s the case, then the way to go is to use a try ... catch
block and handle any instances of QueryException
:
try {
// Get the updated rows count here. Keep in mind that zero is a
// valid value (not failure) if there were no updates needed
$count = DB::table('users')->update([
'active' => true
]);
} catch (\Illuminate\Database\QueryException $e) {
// Do whatever you need if the query failed to execute
}