<?php

namespace App\Validation;

class CustomRules
{
    public function check_unique_user(string $str, string &$error = null): bool
    {
        $db = \Config\Database::connect();
        $builder = $db->table('users');
        $exists = $builder->where('user_name', $str)->countAllResults();

        if ($exists > 0) {
            $error = 'User Name already exists.';
            return false;
        }

        return true;
    }
}