Can I use the default laravel validator just like this library validator because I am trying to validate the data and turns out that it is not the same, for example I am trying to validate the rows in the excel file while importing it using required_with and required_without, for example in the normal validator I used this code:
Validator::make($request->all(), [
'ar_name' => 'required_without:en_name|string',
'ar_description' => 'required_with:ar_name|string',
'en_name' => 'required_without:ar_name|string'
]);
and when I am passing the en_name it won't ask for the ar_name and the same happens when I pass the ar_name it asks for the ar_description and it doesn't care about the en_name
But when I used these validation rules in the import file:
return [
'ar_name' => 'required_without:en_name|string',
'ar_description' => 'required_with: ar_name|string',
'en_name' => 'required_without: ar_name'
];
When I am filling the en_name it still asks me for the ar_name and it shows this message "The ar_name field is required when en name is not present." and the same thing happens when I fill ar_name field it shows a message the en name field is required.
And I printed the array of data when I viewd the errors and the en_name was filled (had actual data in it) and not null
Another thing that is happening is whether I filled the ar_name or I didn't the ar_description field always shows me that is should be a string "The ar_description must be a string.", I mean it doesn't check on the ar_name field and I think he reads it like the field is always required.
Can you help me?
Thanks in advance
I believe it has to be required_without:*.en_name as we validate multiple rows at once
So it actually worked for the required_with and required_without validation, thank you.
But the other thing that kept happening is when I am filling the en_name the ar_name and the ar_description kept giving me that the validator failed because they have to be strings but they aren't even required and I couldn't figure out how to solve it.
the current code:
return [
'ar_name' => 'required_without:*.en_name|string',
'ar_description' => 'required_with:*.ar_name|string',
'en_name' => 'required_without:*.ar_name|string'
];
Thanks
@mhd-yasser-haddad sounds more like a Validation specific question, as it's just Laravel validator, you might find people who can help you better with this on a forum like Laracasts for Stackoverflow.
As I stated in the issue above I tried using the same validation rules using the Validator class in an api and I inserted a code for the validation the I used and everything worked fine, But when I tested the same rules in the laravel excel validation this issue came out of no where.
Do have any resource I could use to maybe find a solution for my issue? I would be very glad.
I am going to post about this issue in laracasts to see if anyone else faced the same issue, and if I found a solution I'll come back here and post it.
Most helpful comment
I believe it has to be
required_without:*.en_nameas we validate multiple rows at once