Validation of Identification card fields (string and array) I am validating two variables of an Identification card (cedula in the code). The first one is a string and the second is an array.

My inputs are:


1- e.g. 3-728-2208
2- e.g. array('1' =&gt; '3-728-2208', '2' =&gt; '1-728-2208')


My method is :

public function validateId($cedula)
{
    $rules = ['cedula' =&gt; 'cedula'];

    $input = ['cedula' =&gt; $cedula];
    if(is_array($cedula))
    {
        $validator = $this-&gt;validateIdIsArray($cedula);
    } else {
        $validator = Validator::make($input, $rules);
    }

    return !($validator-&gt;fails());
}


public function validateIdIsArray($cedula)
{
    $rules = ['cedula' =&gt; 'cedula'];

    foreach ($cedula as $ids) {
        $input = ['cedula' =&gt; $ids];
        $validator = Validator::make($input, $rules);
    }

    return !($validator-&gt;fails());
}


My method from Rule:

public function passes($attribute, $value)
{
   return preg_match('/^((\d{1,2}|N|E|PE|\d{1,2}PI)-\d{1,5}-\d{1,6})$/u', $value);
}
Your code looks good, but I notice that you are a Portuguese speaker (as I am), so my only advice would be: Code in English.

There is a good article about idioms and programming called "Why you shouldn’t code in Spanish". In the article the author even uses PHP in the scripts as examples.

Like the old saying: 


  "Always code as if the person who ends up maintaining your code is a
  violent psychopath who knows where you live."


We should code our code in a way that the majority of programmers will understand, so in a way we should (almost always) code in english.