Need help with validation in cakephp3

My solution, at this point, is just to perform an “exists()” call on the table object:

$container = $this->Containers->patchEntity($containers, $this->request->data);
if ( $this->Containers->exists([ 'name' => $container->name, 'site_id' => $container->site_id ]) ) {
    $this->Flash->error("Container with that name already exists at this site");
} else {
    // Perform normal save operation.
}

Similar code exists in the ‘edit’ method.

I would prefer to handle this in the proper place: the validation rules for model table class.