FilenameHasDossierCode.php
1 <?php 2 3 namespace App\Rules; 4 5 use Illuminate\Contracts\Validation\InvokableRule; 6 7 class FilenameHasDossierCode implements InvokableRule 8 { 9 /** 10 * Run the validation rule. 11 * 12 * @param string $attribute 13 * @param mixed $value 14 * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail 15 * @return void 16 */ 17 public function __invoke($attribute, $value, $fail) 18 { 19 preg_match_all('/(\d{4}-\d{2}-\d{2}_\d{4}-\d{2})/', $value, $matches); 20 $result = $matches[0]; 21 22 if (count($result) !== 1) { 23 return $fail(__('validation.inbox.filename.includes_valid_dossier_code')); 24 } 25 } 26 }