Laravel allows you to create Requests to validate fields from the front end, but I wanted to do several Requests to validate a giant form. It's possible? Is it a good practice?
I made Traits so that they could register for each one.
This is the form field: As you can see, they are divided into array
Thisisthemethodinthecontrolleryouarereceiving:
publicfunctionstore(DealerRequest$request){try{DB::beginTransaction();dd($request->all());$dealer=$this->dealer->create($request['dealer']);$company=$this->createCompany($dealer,$request);$this->createPerson($company,$request);$this->createLocation($company,$request);$this->createContact($company,$request);$this->createContract($company,$request);DB::commit();event(newWelcome($dealer));returnredirect()->route('representative.dealers.index');}catch(\Exception$e){dd($e->getMessage());DB::rollBack();returnredirect()->back()->withInput()->with('error','Falhanoservidor');}}
Thismethodmakescallstoothermethodsthatperforminsertsinthedatabase.Myideawasforeachmethodtohavearequestvalidatingtheirrespectivefields.
Example:
publicfunctioncreateCompany(Dealer$dealer,CompanyRequest$request){try{return$dealer->company()->create($request->input());}catch(\Exception$e){return$e->getMessage();}}
Thisisamethodthatinstantiatesarequest,andhowitinstantiatesitsrequests.butwhenrunningIgetthefollowingerror:
I would like a better solution, or how to solve this problem.
Thank you !!