Laravel Tip: What's the Difference Between setParameter() and request->add()??
Confused between $request->route()->setParameter() and $request->request->add() in Laravel? This quick guide breaks down the difference, use cases, and best practices. Learn when to use each to keep your code clean, efficient, and Laravel-ready.

When working with Laravel requests, you might come across these two similar-looking lines:
1. setParameter()
: Adds a Route Parameter
Example:
Now you can access it using:
What it does
This modifies the route parameter, not the usual input data. Under the hood, Laravel’sRoute
object keeps a list of parameters that were extracted from the URI (and also any you manually set). By callingsetParameter()
, you’re telling Laravel “for the currently matched route, pretend that there was a{layout}
wildcard in the URI whose value is$layout
.”Where it shows up
In your controller or middleware, you can later retrieve it via
$request->route('layout')
If your route definition includes something like
/posts/{layout}
, URL generation (route('posts.show', ['layout' => 'grid'])
) and URL matching will use this parameter.
Typical use cases
Dynamically influencing route model binding
Generating URLs with a “virtual” route parameter
Middlewares that alter how the route is resolved
2. request->add()
: Adds POST/Form Input
Example:
Now you can access it using:
What it does
This injects data into the “request payload” bag—that is, the same place where$_POST
(and$_PUT
, etc.) lives. In Symfony (which Laravel’s HTTP layer is built on), theParameterBag $request
holds form‐input data. So callingadd()
simply makeslayout
appear as if the client had submitted it in the body of the request.Where it shows up
In your controller or middleware, you can retrieve it via
$request->input('layout')
or$request->get('layout')
Validation (
$this->validate($request, ['layout' => 'required|string'])
) will see it as part of the submitted dataMass‐assignment via
$model->fill($request->all())
will include it
Typical use cases
Adding or overriding form data before validation
Injecting default values into the request payload
Preparing input for service classes, import routines, etc.
Summary
Aspect | route()->setParameter() | request->add() |
---|---|---|
Bag | Route parameters | HTTP request payload ($_POST etc.) |
Retrieval | $request->route('layout') | $request->input('layout') |
Affects URL gen? | Yes (in URL generation and route matching) | No |
Validation sees it? | No (unless you manually map route params in) | Yes |
Use when… | You want to influence routing/URL building | You need to add or override input data |
Choose the one that matches your goal:
If you need the value to act like a URL/route parameter (in route model‐binding, URL generation, middleware logic that reads route params), use
setParameter
.If you need the value to act like submitted form data (for validation, mass‐assignment, or business logic off
$request->input()
), useadd()
.
Pro Tip
Always choose based on context:
Need it for routing or URLs? Use
setParameter()
.Need it for form validation or business logic? Use
request->add()
.
💡 Stay sharp and explore more Laravel tips at Tutorial Tools!