Search code examples
laravelurlenvironment-variableslaragon

URL generator putting "localhost" before domain in Laravel


I've been trying to email users a verification link using signed URLs in Laravel. It seems to work okay, but the link comes out incorrect when it is built using the URL facade.

public function toMail($notifiable)
{
    $url = URL::signedRoute('confirm', ['user' => $this->user->id]);

    return (new MailMessage)
                ->subject('Activate your email address')
                ->line('In order to use the application, please verify your email address.')
                ->action('Activate your account', $url)
                ->line('Thank you for using our application!');
}

In the email, the link looks like:

http://localhost/mydomain.com/confirm/14?signature=3ba4d86827717440f70a3b2f60c913b6e84d550cb9fce8de04a8ba359833ac7c

The "localhost" part should not be there. However, if I manually delete it in the URL bar, I believe the signed URL things I manipulated the URL and gives me a 401 error. I am running on a localhost environment but I use Laragon's auto virtual host so that I can still run it with a domain.

Any suggestions?


Solution

  • Change:

    APP_URL=example.com

    To:

    APP_URL=http://example.com

    I guess not specifying "http://" makes it append localhost to the front. Hope this helps someone!