2

Continuing discussion from here

If we have two Requests like:

public function store(FirstRequest $request, SecondRequest $request) { ... }

is it possible to run both Requests and not one after another. This way if validation doesn't pass for FirstRequest, SecondRequest won't start and it will create error messages only after FirstRequest passes without any errors.

Community
  • 1
  • 1
dbr
  • 1,037
  • 14
  • 34
  • for laravel 5.5 : https://stackoverflow.com/questions/48370879/laravel-5-5-validate-multiple-form-request-at-the-same-time/48371383#48371383 – iamab.in Jan 21 '18 at 21:11

1 Answers1

1

I think that you can "manually creating validators"

http://laravel.com/docs/5.1/validation#other-validation-approaches

Basically in your method instead of use a a Request injection, use the rules directly in the method and call the $validator->fails() method for every set of rules.

Something like this:

public function store(Request $request){

    $rulesFirstRequest = ['field1' => 'required', 'field2' => 'required'];
    $rulesSecondRequest = ['field12' => 'required', 'field22' => 'required'];

    $validator1 = Validator::make($request->all(), $rulesFirstRequest);
    $validator2 = Validator::make($request->all(), $rulesSecondRequest);

    if ($validator1->fails() && $validator2->fails()) {
      //Do stuff and return with errors
   }
   // return with success
}

Hope it helps

JuanDMeGon
  • 1,191
  • 1
  • 11
  • 20
  • This is a valid workaround but not what I hoped for. Though, as @lukasgeiter noted, it's possible that it can't be done using Requests. I'll upvote it but leave as unanswered for now. – dbr Aug 31 '15 at 13:46