Home > Software design >  how to add data to validated request input bag
how to add data to validated request input bag

Time:01-09

I need to add custom data to the request input array from my customRequest class

I tried this way

request()->request->add(['cool' => request()->get('var1').request()->get('var2')]);

It's do the trick with request()->all() but when I returned $request->validated() it's not exist.

how can I do it?

CodePudding user response:

You can merge with new array

array_merge(request()->all(), ['cool' =>  request()->get('var1').request()->get('var2')]);

CodePudding user response:

$request->validated() is returning only validated data (data in the request validator class).

After validating the data you can add additional data in the request using

$request->merge(['cool' => request()->get('var1')]);

Laravel documentation: https://laravel.com/docs/8.x/requests#merging-additional-input

  •  Tags:  
  • Related