问题
When I call any of the url helper functions, e.g
URL::asset('foo/bar')
from within a command the base URL is an empty string, and the url returned is
http://:/foo/bar
I am running the command by calling
php artisan myproject:MyCommand
from a command line. Where MyCommand is a class that extends Illuminate\Console\Command
I have set my url in config/app.php but I only get a fully qualified url when I run from an HTTP Request
I am using Laravel Framework version 4.1.24
回答1:
Where did you get URL::asset('')
from? I don't see it mentioned on the documentation
Try this instead:
URL::to('foo/bar')
回答2:
Found the issue.
My artisan file was missing this line
$app->setRequestForConsoleEnvironment();
The file I had was an older version. This line was added Oct 25, 2013
来源:https://stackoverflow.com/questions/22498468/url-helper-functions-within-an-artisan-command-return-empty-base-url