I'm handling data in one controller and want to pass it further into another controller to avoid duplicate code.
Is there a way to set up a Request object that is needed in the other controller's store
-method? I've traced down the Request inheritance and came to Symfony's Request object which has a request
property that is in fact a ParameterBag
that holds a method add
to add parameters with values to it.
I've tried the following but I'm getting null
as result:
$myRequest = new Request(); $myRequest->request->add(['foo' => 'bar']); var_dump($myRequest->foo);
I'm on Laravel 5.1 for this project.
You can use replace() : $request = new \Illuminate\Http\Request(); $request->replace(['foo' => 'bar']); dd($request->foo); Alternatively, it would make more sense to create a Job for whatever is going on in your second controller and remove the ShouldQueue interface to make it run synchronously. Hope this helps!
input() is a method of the Laravel Request class that is extending Symfony Request class, and it supports dot notation to access nested data (like $name = $request->input('products.0.name') ).
The hashName method is exactly what Laravel calls in the store method. $request->image->hashName(); You will get the same name that Laravel generates when it creates the file name during the store method. $path = $request->image->getClientOriginalName();
You can use replace()
:
$request = new \Illuminate\Http\Request(); $request->replace(['foo' => 'bar']); dd($request->foo);
Alternatively, it would make more sense to create a Job
for whatever is going on in your second controller and remove the ShouldQueue
interface to make it run synchronously.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With