Laravel absolute URLs from background queue

laravel-logoFor a project I use background queues to send confirmation emails. In the Blade template of this email I use the link_to_route() helper function. But when sending the emails through the background queue the domain for this link defaulted to localhost.

Normally Laravel falls back to the domain of the request, but that is not available when code runs in the background queue. I fixed this by adding the following line of code to the register() method of my AppServiceProvider:


$this->app['url']->forceRootUrl('http://www.example.com');

In my case I also added a APP_URL environment variable, because I want to set the correct URL for all environments of the app, and chaged the code to the following:


$this->app['url']->forceRootUrl(env('APP_URL'));
December 7, 2015

Click Here to Leave a Comment Below

Leave a Reply: