A URL created using Laravel consists of several parts:
- Schema:
http:// , https:// etc. - Host:
dev.domain.com , localhost , etc. - Base:
something/somethingElse (subdirectory on the web server) - Tail:
myRoute , (Laravel route parameters)
These parts are then combined to form a URL.
Ultimately, Laravel generates the URL using the $_SERVER query $_SERVER . The prepareBaseUrl() function in Symfony\Component\HttpFoundation\Request is what is ultimately used to determine the base portion of the URL.
When you make a request through your web browser, the request is sent to ~/public/index.php , and the necessary $_SERVER are populated with the correct information for Laravel to fill in the base part of the URL.
However, when you make a request using Artisan on the command line, the request goes to ~/artisan script. This means that the $_SERVER not populated the same way, and Laravel cannot determine the base portion of the URL; instead, it returns an empty string. ''
From what I can find, it doesn't look like the Laravel team has an appetite so that the application can function out of the box in a subdirectory, for example. Bugfix: domain routing for a subfolder .
I ended up working on this method described by @medowlock for my scripts that will be invoked from the command line, for example:
Config::get('app.url') . URL::route('route.name', ['parameter'=>'value'], false)
This combines the application URL specified in app/config/app.php and the relative URL route.
source share