when I submit the form, I want to compare two input values at the time of validation in Controller store function
array(
'name' => 'required',
'password' => 'required|min:8',
'email' => 'required|email|unique:users',
'rule'=>'input1'<'input2',
)
I assume your rule property is not really an input field on the form or data. Because if rule is a property, like email, then I don't know what you want to validate it against. (rule is only valid if input1 is smaller than input2?)
Maybe you actually want to validate the input1 attribute like this:
array(
'name' => 'required',
'password' => 'required|min:8',
'email' => 'required|email|unique:users',
'input1'=> 'lt:input2',
)
Do mind that input1 and input2 must be of the same type.
See: https://laravel.com/docs/5.8/validation#rule-lt
Related
I want to unique validation a input field from multiple table. But i don't know how to do this. I already try some way but nothing work. Here is my code.
$validate = Validator::make($request->all(), [
'gender' => 'required|max:5',
'email' => 'required|unique:customers,email|unique:subscribers,email|max:128',
]);
You can use the unique rule twice, like so:
$validate = Validator::make($request->all(), [
'gender' => 'required|max:5',
'email' => 'required|unique:customers|unique:subscribers|max:128',
]);
You also don't have to provide the column name, if you leave it unspecified laravel will assume the field name, which is also email in this case.
I have 2 different tables based on their types: User & Buyer.
I am validating "buyers" data but it checks in the "users" table rather than in the "buyers" table, Is there any way to ask Validator Facade to check in the "buyers" table.
$validator = Validator::make($request->all(), [
'name' => 'required',
'user_type' => 'required',
'phone' => 'required|unique:users|max:11|min:11',
'email' => 'required|email|unique:users',
'password' => 'required|min:8',
'passowrd_confirmation' => 'required|same:password',
]);
https://laravel.com/docs/8.x/validation#specifying-a-custom-column-name
According to the documentation, you can indicate a specific field of any of your tables for validation. In this way you can do:
'name' => 'required:buyers, name'
I have a field called title in table languages.
While creating a new user using register form, user has a option to either chose existing or create a new language. How do I make sure the language created is unique?
users table is different and languages table is different.
my current validation code in create method (Registercontroller)
'firstname' => 'required|max:255',
'lastname' => 'required|max:255',
'email' => ['required','max:255','unique:users','regex:/(#org.uk)$/',],
'password' => 'required|min:6|confirmed',
'title' => 'required',
I want to add something like: unqiue:languages but how do I do that? do I set langauge field to unique?
laravel validation for unique
here is the solution what you needed . In unique validation it check new entry was unique or not what you do is this just simply given the desired table name and field from which you want to check field is unique or not
'firstname' => 'required|max:255',
'lastname' => 'required|max:255',
'email' => ['required','max:255','unique:users','regex:/(#org.uk)$/',],
'password' => 'required|min:6|confirmed',
'title' => 'required|unique:languages,title',
hope this will help you
I use soft deletes which I then ignore/exlude in the validation rules in Laravel 5.3.
How do I enforce two ignores in a validation array for updates?
'number' => "required|unique:customers,number,NULL,id,company_id,
$company_id},deleted_at,NULL",
I need to add the exclusion of the current record as well.
I found the answer myself. For your information(field = number) :
$validator = Validator::make($request->all(),
[
'number' => "required|unique:customers,number,{$id},id,company_id,{$company_id},deleted_at,NULL",
'name' => 'required',
'street' => 'required',
'streetnumber' => 'required',
'zipcode' => 'required',
'city' => 'required',
]);
I'm using Tank Auth (it's working fine), but I can't get the form validation function to work when I include any value in the variable array along with set_value. I need these values as a label for form fields--they tells the user what to enter in the field.
How can I keep Tank Auth's form validation functionality AND use a value in the value field?
$login = array(
'name' => 'login',
'id' => 'login',
'value' => set_value('login', 'Enter username'),
);
this populates field values : set_value('field_name');
this shows individual errors: form_errors('field_name');
If you use html5, you can simply add a placeholder!
{ placeholders should not be used as an alternative to labels!}
$login = array(
'name' => 'login',
'id' => 'login',
'value' => set_value('login'),
'placeholder' => 'Enter Username',
'required' => 'required'
);