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.

2
  • 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, stackoverflow.com/questions/19952572/… Commented Apr 13, 2014 at 17:29
  • possible duplicate of Laravel 4 route with unlimited number of parameters Commented Apr 14, 2014 at 6:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.