I have a controller where URL::to('/') returns the base url of my website. However, when I use URL::to('/') in a job, it returns only a colon as a string (":").
class MyJob extends Job {
public function handle() {
Log::info(URL::to('/'));
}
}
This returns "http://:"
class MyController extends Controller { {
public function myMethod() {
Log::info(URL::to('/'));
}
}
This returns "http://my_domain.com"
I can't make sense of this. Should I just save the base url in the .env and use that?
I am using beanstalkd for queues.
Naturally
UrlGenerator
class gets the base url off of aRequest
instance https://github.com/laravel/lumen-framework/blob/5.0/src/Routing/UrlGenerator.php#L289 which doesn't exist when you run your job worker in the CLI environment.Therefore either store the base url in your .env file or pass it to your job when you dispatch it.
MyJob.php