Laravel - Request::server('HTTP_HOST') returns 'localhost' from within a helper class

Adamski picture Adamski · Apr 15, 2014 · Viewed 13.8k times · Source

I want to get the current domain, using Request::server('HTTP_HOST') - however when I call this from within a helper class it comes back as 'localhost' which is not what I want. From a controller it works as expected. Is there a way to access this information from within a helper class?

The helper class looks like this:

class ApiWrapper {
    public static function call($model, $method='', array $input) {



        $domain = Request::server('HTTP_HOST');
    }
}

Answer

SUB0DH picture SUB0DH · Apr 15, 2014

You can do URL::to('/') to get the base URL of the Laravel application, if that's what you're asking for. If doing Request::server('HTTP_HOST') from your controller is giving you the desired result, doing the same from the helper class shouldn't be any different.