2

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');
    }
}
Adamski
  • 3,585
  • 5
  • 42
  • 78

1 Answers1

6

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.

SUB0DH
  • 5,130
  • 4
  • 29
  • 46
  • Thanks however I still get 'localhost' from URL::to('/') from the helper class. Wonder if I need to include anything in the helper so it can access those session variables? – Adamski Apr 16 '14 at 09:55
  • @Adamski having the same issue. Did you find a fix? – A F Sep 08 '14 at 14:16
  • @AakilFernandes sorry I don't think I did - that project was abandoned, and looking at the code I still had the URL hard-coded. – Adamski Sep 09 '14 at 09:50
  • @Adamski. No worries. I ended up just using environment switches and hardcoding. Not a great fix but I suppose it works for now. – A F Sep 09 '14 at 14:08