Support the ongoing development of Laravel.io →
posted 9 years ago
Requests

Is there a way to pass data (that is not a route parameter but just hardcoded data) to a controller from a route definition? Preferably this would not happen in a closure but I understand if that is the only way.

For instance, let's say that I have 2 routes. One of them can take a route parameter and pass that in to a controller method. The second route does not take any parameters but calls the same controller function and passes that data in hardcoded from the routes file.

Route::get('test/{id}', 'TestController@index');
$id = 214;
Route::get('something', 'TestController@index'); //this should pass $id to the controller method

Obviously I am aware that in such a simple example, I can accomplish this with optional parameters, but my real use case is more complicated.

I am looking for something like this, although I know this does not exist:

Route::get('something', ['uses' => 'TestController@index', 'with' => 214]);
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.