URL helper functions within an Artisan command return empty base URL

帅比萌擦擦* 提交于 2019-12-25 02:37:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!