1
votes

this is inside the database: enter image description here

.

and the html form:

<form>
    <input type="text" name="fc_fullname" placeholder="Full Name" />
    <input type="email" name="fc_email_addr" placeholder="Email Address" />
    <input type="password" name="fc_pwd" placeholder="Password" />
    <input type="password" name="fc_pwd_confirmation" placeholder="Repeat Password" />
</form>

.

and the validation code is:

Validator::make($request->all(), [
        'fc_fullname' => 'required|string|max:255|exists:admins,name',
        'fc_email_addr' => 'required|string|email|max:255|unique:admins,email',
        'fc_pwd' => 'required|string|min:6|confirmed|exists:admins,password',
])->validate();

.

.

So, currently, I am able to use custom column name by using exists and unique Validation rules.

But I don't want to use the exists rule. I just want to specify custom column name ONLY.

Is there any other rules or trick to specify the column name in database table?

1
Hello, what are you trying to achieve here? If you use exists, it will check if the inserted value already exists in the column. For example, if you check it for password, the inserted password will check if it is already available in the password column of admins table. But the password should be encrypted. So what are you looking for actually?Ahsan
yes i know... exists will check if the value exist in the table. If value already exist, the value is VALID. And for unique, it also will check if the value exist in the table. But for this rule, if value already exist, the value is INVALID. I already state 'What I want try to achieve' in the question. Stackoverflow is for all people around the world, so you should be ready to understand english in different slang or different accent. By the way, answer from @GAURAV VAGHELA is what I am looking for. I already mark his answer as the correct answer. ThanksSyamsoul Azrien

1 Answers

3
votes

Yes You can try this.

$attribute = array(
   'fc_fullname' => 'name',
   'fc_email_addr' => 'email',  
   'fc_pwd' => 'password',
);

$validator = Validator::make ( Input::all (), $rules );
$validator->setAttributeNames($attribute);