2

I have the following code in my routes file:

$domain1 = 'www.domain1.co.uk';

Route::group(array('domain' => $domain1), function() use ($domain1)
{
    Route::get('/', 'PrimaryController@index');
});

How can I pass the variable $domain1 to the controller method?


To expand to a more general question, how can I simply declare some variable in my routes file and then pass it to a controller? I know I can do this:

Route::get('tours/{id}/{title}', 'PrimaryController@tourHandler');

...and have access to the $id and $title variables in the controller- Which is great if those variables are present in the URL. But what if, for whatever reason, I want access to some specific variables which I want to set myself in the routes file?

Laravel seems too clever sometimes.

Inigo
  • 8,110
  • 18
  • 62
  • 110
  • In this situation you could use `Config::set()`. If you were to have the custom variable available to the controller, probably you would have to set it at `App::before()` and make it available to routes and controllers. Please check this link, if you haven't already, http://stackoverflow.com/questions/19952572/global-variable-in-laravel-4 – user2094178 Apr 13 '14 at 17:29
  • possible duplicate of [Laravel 4 route with unlimited number of parameters](http://stackoverflow.com/questions/21522677/laravel-4-route-with-unlimited-number-of-parameters) – Gadoma Apr 14 '14 at 06:52

0 Answers0