dimanche 20 septembre 2015

PHP Laravel 5 Making Validator Rule to check if account with specific type exists

I'm struggling with making this validation rule. In my 's_accounts' table I have two rows: acc_name (stores the name of the account) and acc_type (stores the type of account). Before when I was working with only one account type I had created the following validator rule which made sure that the acc_name was unique:

$rules = array('acc_name' => 'unique:s_accounts,acc_name');
        $input['acc_name'] = $username;
        $validator = Validator::make($input, $rules);

        if ($validator->fails()) {
            // account already exists
        }
        else {
       // proceed
       }

Now that my application can make two types of accounts, i want it to be able to have two accounts with the same acc_name as long as the acc_type is different. In order to do this, i need to change this validation rule to include $input['acc_type'] = "X";

What i need help with is changing the rule array so validation fails if an account with the same acc_name and acc_type exists but doesn't fail if the acc_name with a different acc_type exists?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire