Get the subdomain in a subdomain-route (Laravel)

$subdomain is injected in the actual Route callback, it is undefined inside the group closure because the Request has not been parsed yet.

I don't see why would you need to have it available inside the group closure BUT outside of the actual Route callback.

If want you want is to have it available everywhere ONCE the Request has been parsed, you could setup an after filter to store the $subdomain value:

Config::set('request.subdomain', Route::getCurrentRoute()->getParameter('subdomain'));

Update: applying a group filter to setup a database connection.

Route::filter('set_subdomain_db', function($route, $request)
{
    //set your $db here based on $route or $request information.
    //set it to a config for example, so it si available in all
    //the routes this filter is applied to
    Config::set('request.subdomain', 'subdomain_here');
    Config::set('request.db', 'db_conn_here');
});

Route::group(array(
        'domain' => '{subdomain}.project.dev',
        'before' => 'set_subdomain_db'
    ), function() {

    Route::get('foo', function() {
        Config::get('request.subdomain');
    });

    Route::get('bar', function() {
        Config::get('request.subdomain');
        Config::get('request.db');
    });
});

Shortly after this question was asked, Laravel implemented a new method for getting the subdomain inside the routing code. It can be used like this:

Route::group(array('domain' => '{subdomain}.project.dev'), function() {

    Route::get('foo', function($subdomain) {
        // Here I can access $subdomain
    });

    $subdomain = Route::input('subdomain');

});

See "Accessing A Route Parameter Value" in the docs.