Check Record exists in database

$user = $this->Users->newEntity();
if ($this->request->is(‘post’)){
$number = $this->request->data[‘number’];
$num = $this->Users->findByEmail($number)->select([‘number’])->hydrate(false)->first();

		if(!$this->Users->exists($num)){				
			$user = $this->Users->patchEntity($user, $this->request->data);
			$this->Users->save($user);
			echo "1";
    	}
		else{
			echo "There is another...";
		}
	}
    $this->set(compact('user'));
    $this->set('_serialize', ['user']);
}

You didn’t ask a question, but it looks like you are trying to validate that a form field corresponding to a database column contains a unique value. You could simply add a custom validation to the UsersTable.php $validator:

->add(‘email’, [
‘unique’ => [
‘rule’ => ‘validateUnique’,
‘provider’ => ‘table’,
‘message’ => ‘This email is already associated with an active account’
]
])