Skip to content
Advertisement

how to add data to validated request input bag

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?

Advertisement

Answer

$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

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement