Saturday, March 11, 2017

How to add validation on same database field for different names in Laravel?

I have a database users. It has an email field.

I have two input fields with names users[email] and manager.email. I want the validation of uniqueness to be on users table. Here is what have I tried it.

<div class="row">
    <div class="form-group col-md-12">
        <div class="col-md-8"></div>
     </div>
</div>

<div class="row">
    <div class="form-group col-md-12">
        <div class="col-md-8"></div>
     </div>
</div>

My validator is as follows:

$validationRules = ['users.email' => 'email|required|unique:users', 
'manager.email' => 'email|required|unique:users', 
];

So, when I validator it returns a message stating :

Unknown column 'manager.email' in 'where clause' (SQL: select count(*) as aggregate from `users` where `manager`.`email` = 'xyz@email.com')

Please guide me through this or suggest me a better option to resolve this problem.



via Nevermore

Advertisement