vendredi 1 juillet 2022

how to use custom rule in middleware of laravel 9.x?

NOTE: this is for an endpoint. not for a form request.

let's say I have middleware named Inputs which has this code in the handle()

public function handle(Request $request, Closure $next) {

  $data = $request->all();
   
  foreach ($data as $array) {
      //HOW TO USE THE CUSTOM RULE HERE?
  }
  return next($request);

}

here's the custom rule App\Rules

class MyRule {


  public function construct() {}

  public function passes($attribute, $value) {
       if ($value > 1) {
          return false;
       }
      return true;
  }

  public function message() {
      return "data invalid";
  }

}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/x90Syqk
via IFTTT

Aucun commentaire:

Enregistrer un commentaire