Create a Laravel Request object on the fly
You are encountering a common architectural pattern: extracting shared logic from one controller and injecting it into another to eliminate duplication. In your specific case, you've identified that Illuminate\Http\Request extends Symfony's Symfony\Component\HttpFoundation\Request. You found the request property, which is an instance of Symfony\Component\HttpFoundation\ParameterBag, and you discovered its add() method.
Your current approach attempts to instantiate a new request object manually, populate the underlying bag, and then access the data directly via the $foo property on the main object. This results in null. The issue isn't with your use of the ParameterBag; it is with how Laravel's Request class exposes its internal state.
The Illuminate\Http\Request class does not implement magic methods to automatically populate its public properties from the underlying ParameterBag. When you access $myRequest->foo, Laravel expects the data to reside in the input or attributes bags, depending on where the input was originally parsed. By calling $myRequest->request->add(), you are modifying the bag directly, but the parent class has not yet bound that data into its own property map.
To make this work without relying on internal Symfony implementation details or magic methods, you must explicitly tell the Request object where to store the new data. The Illuminate\Http\Request class provides a dedicated method for this exact scenario: merge(). This method accepts an array and unifies it with the request's input and attributes bags, respecting the standard Laravel parsing hierarchy.
Here is the corrected implementation that will yield the expected result:
use Illuminate\Http\Request;
$myRequest = new Request();
// Use merge() instead of directly manipulating the internal bag
$myRequest->merge(['foo' => 'bar']);
var_dump($myRequest->foo); // Outputs: "bar"
By using merge(), you are leveraging the public API of the Illuminate\Http\Request class. This ensures that any validation rules, middleware, or other logic attached to a standard request instance can access the data immediately after creation. If you were to persist with the add() method on the inner bag, you would be bypassing Laravel's input resolution layer, which could lead to inconsistencies if other parts of your application expect data in specific bags (like attributes for non-standard fields or input for form data).
Trade-offs and Architectural Considerations
While creating a fresh Request object allows you to pass state between controllers cleanly, it comes with significant caveats. The most critical pitfall is the lack of middleware context. A standard Laravel request is processed through a pipeline of middleware that handles authentication, CSRF protection, rate limiting, and logging. When you instantiate new Request() manually, this data is missing.
If your second controller relies on $request->user(), $request->route(), or any middleware-modified input, your manual instantiation will fail silently or return default empty values. The store method in a standard controller often assumes the request has already been parsed against the current route's parameters and headers. A raw Request object lacks this context unless you manually populate every single attribute.
The Better Alternative
If your goal is strictly to avoid code duplication between controllers, consider using Laravel's Form Request validation classes or simply extracting a shared method into a Service Provider or Repository. Passing a fully hydrated request object around without the middleware stack often defeats the purpose of Laravel's routing system.
However, if you are building a reusable component that accepts a request context, ensure you initialize it with the necessary data using merge() to maintain compatibility with Laravel's internal logic. For more complex scenarios involving large payloads or specific validation rules across multiple controllers, reviewing the official documentation at https://laravelcompany.com can provide guidance on structuring your application to minimize manual object manipulation in favor of leveraging the framework's built-in abstractions.
