The example below shows the verification of the id value in deletions of the Companies module. In the deletion verification process, a connection is made to the database and it is checked whether a company exists with the id sent among the existing companies.
src/App/Filter/Companies/DeleteFilter.php
<?php
declare(strict_types=1);
namespace App\Filter\Companies;
use App\Filter\InputFilter;
use Laminas\Validator\Uuid;
use Laminas\Validator\Db\RecordExists;
use Laminas\Db\Adapter\AdapterInterface;
class DeleteFilter extends InputFilter
{
public function __construct(AdapterInterface $adapter)
{
$this->adapter = $adapter;
}
public function setInputData(array $data)
{
$this->add([
'name' => 'id',
'required' => true,
'validators' => [
['name' => Uuid::class],
[
'name' => RecordExists::class,
'options' => [
'table' => 'companies',
'field' => 'companyId',
'adapter' => $this->adapter,
]
]
],
]);
$this->setData($data);
}
}