Laravel Fluent查询根据if行存在更新或插入

I have a Laravel Fluent query that looks like the following:

$query = DB::connection('mysql_users')->table('users_info');
$exists = $query->where('email', '=', $user->email)-first();

if(is_object($exists)) {
    // update email
}
else {
    // insert email
}

The problem is, sometimes $exists is not an object even though the row does exist. I've also tried with is_null() and have had the same issue. What is the correct way to do this check?

Just check the statement, if its not an object then don't check for one.

if($exists = $query->where('email', '=', $user->email)-first()) {
    // update email
}
else {
    // insert email
}