/ app / Rules / ValidateDossierCodeExists.php
ValidateDossierCodeExists.php
 1  <?php
 2  
 3  namespace App\Rules;
 4  
 5  use App\Http\Services\DossierService;
 6  use Illuminate\Contracts\Validation\InvokableRule;
 7  
 8  class ValidateDossierCodeExists implements InvokableRule
 9  {
10      /**
11       * Run the validation rule.
12       *
13       * @param  string  $attribute
14       * @param  mixed  $value
15       * @param  \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString  $fail
16       * @return void
17       */
18      public function __invoke($attribute, $value, $fail)
19      {
20          if (DossierService::findByCode($value) === null) {
21              $fail(__('validation.attributes-custom.validate_dossier_code_exists') . ' ' . $value);
22          }
23      }
24  }