Dom
Dom

Reputation: 3444

How to validate a lang and a country id with Laravel?

I would like to validate a lang and a country with Laravel validation. I wonder if it exists something like that:

$validator = Validator::make($request->all(), [
    'branch_id' => 'required|uuid|exists:branches,id',
    'language_id' => 'required|**valid**',
    'translation' => 'required',
    'country_id' => 'required|**valid**'
]);

A function like the valid I wrote: 'language_id' => 'required|**valid**'

How would you do that?

Edit : I do not want to manage countries and languages in tables. I would like to validate or not the country and language with their name. For example 'fr' is a valid language and 'FR' is a valid country. But 'zz' is not a valid language.

But perhaps the good practice would be to have these countries list and languages list in a table (or array) ?

Upvotes: 0

Views: 378

Answers (1)

Dom
Dom

Reputation: 3444

I give up on my initial idea (validate the country with a rule). I will simply check with this array I found:

https://gist.github.com/vxnick/380904

Upvotes: 1

Related Questions