Skip to content

url helper not picking the base root from the config setting #17385

@amosmos

Description

@amosmos
  • Laravel Version: 5.3.22
  • PHP Version: 7.0
  • Database Driver & Version: N/A

Description:

When using the url helper, the root is calculated by symfony and not picked up according to the APP_URL env variable.

I found out about it when I was trying to use the url helper in an email notification which was sent based on an eloquent event listener (placed in a service provider) while running the app on homestead. The helper didn't pick up the 8000 port. After checking it I noticed the helper is using the request root function which is calculating the root based on a prepareBaseUrl symfony function (look here: https://github.com/laravel/framework/blob/5.3/src/Illuminate/Http/Request.php#L87, while the getBaseUrl is calling prepareBaseUrl), and that function somehow miss the port number in this specific call (from a service provider). So even when I manually set the 8000 port on the APP_URL env variable, nothing changed.

Note - when the email notification was called regularly from a controller, the port was received correctly. It only happened to me when the notification was called from a service provider.
Also, I believe on production there shouldn't be a problem as you don't need a special port like when using homestead.

Steps To Reproduce:

  1. Create a laravel app locally on homestead.
  2. Create a mail notification and place a url() helper call in it to some link or asset.
  3. Create an eloquent event listener in a service provider (for example appServiceProvider (for example a listen to a model creation event) which then sends the email notification.
  4. Create that model to invoke the listener and the notification sending.
  5. Look at the returned URL created with the url helper and see there is no 8000 port.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions