简体   繁体   中英

URL helper functions within an Artisan command return empty base URL

When I call any of the url helper functions, eg

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

Where did you get URL::asset('') from? I don't see it mentioned on the documentation

Try this instead:

URL::to('foo/bar')

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM