Vue Vee validate in Laravel method unique - laravel

Laravel validate has method unique but vue-vee validate doesn't has it. How can i use unique in vue-vee validate? (I mean v-validate='')
For example in laravel:
return $validator = [
'title' => 'required|unique:rubrics,title',
];
In advance thanks for help.

Related

Laravel Active Validation Rule

I am extremely new to Laravel and I was wondering if you could help me create a Custom Validation Rule, I am using version 5.5 of Laravel.
What I try to do is the following, I understand that the validations can be defined in the following way:
'email' => 'required|string'
I would like to add a new rule, in specific one called 'active'
In the application that I want to create I have several tables in which there are columns called 'active' (boolean) .. example
Users:
id|name|email|active
Roles:
id|name|active
I need a rule that I can call as follows:
'email' => 'required|string|active'
In short, I need a rule that verifies in a specific table, if the value I'm validating is active, and if not, send me a message. Thank you very much in advance
Try to use the Rule class and 'exists' validation:
use Illuminate\Validation\Rule;
'email' => [
'required',
'string',
Rule::exists('your_table')->where(function ($query) {
$query->where('active', 1);
}),
]

How should I validate two-dimensional array in laravel

I am new learner of laravel.Now I have to use the laravel validation in my project.The data from the form is two-dimensional array in the follwing format:
[['product_id'=>1, 'quantity'=>2], ['product_id' => 4, 'quantity'=>5]]
I need to validate every product_id, how should I write the validation rule?
thank you!
This will validate the product_id field of each associative array within the form data.
$validator = Validator::make($request->all(), [
'*.product_id' => // your validation rule
]);

Laravel validation of spezific field/value

i have a form field with two options:
{!! Form::select('pet',array('1'=>'Dog', '2'=>'Cat') ,null,['class'=>'form-text']) !!}
is there any way to validate this values via $this->validate($request, [...]) or do i have to do this via if statement?
thanks for any sugestions.
You cant prevent people edit the data
You have to validate the data once you have the request in you server
Could try like this:
$this->validate(request(), [
'pet' => 'required|in:1,2'
]);
so only if pet value is 1 or 2 will pass.
not tested but should work

Email validation rule in Laravel?

I do email validation using the simple rule:
'email' => 'required|email|unique:users,email',
How do I modify the option unique so that it will work only if the entered email is different from the primordial?
A sample:
The field email contains the default value from table users: example#gmail.com
Then I push the button without making any changes in the form I should not check unique:users.
Otherwise, if I even changed one symbol in example#gmail.com1 I must validate the incoming value using: unique:users.
You can find an example here https://laracasts.com/discuss/channels/requests/laravel-5-validation-request-how-to-handle-validation-on-update
You will need to have multiple rules depending on the request method (update or create) and you can pass a third parameter to unique to ensure no fail if you know the user / email
'user.email' => 'required|email|unique:users,email,'.$user->id,
Switch for method
switch($this->method())
{
...
}
I did this using the conditional checks:
$validator = Validator::make($request->all(), []);
$validator->sometimes('email', 'unique:users,email', function ($input) {
return $input->email !== Auth::user()->email;
});
I think it is as loophole in laravel validation.
I update the code for email validation. This is working fine for me.
'email' => [
'required', 'email:rfc',
function($attribute, $value, $fail) {
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
$fail($attribute . ' is invalid.');
}
}],

Validate values in form arrays

I've a post value members and members is an array of values. How can I validate that one specific value is not in the list?
Example
$this->validate($request, [
'member_ids' => 'required|min:1|not_in:4',
]);
Thanks!
Laravel 5.2 has array validation.
So try this:
$this->validate($request, [
'member_ids.*' => 'required|not_in:4',
]);
I am not sure what it is you would like to achieve, but I think you can find a solution from here: http://laravel.io/forum/11-12-2014-how-to-validate-array-input

Resources