Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating route using route() #65

Closed
ivalkenburg opened this issue Jun 28, 2020 · 3 comments
Closed

Generating route using route() #65

ivalkenburg opened this issue Jun 28, 2020 · 3 comments

Comments

@ivalkenburg
Copy link

ivalkenburg commented Jun 28, 2020

When generating routes using route() helper inside a queued job or mail, it will generate the non scoped route. For example: tenant is acme with the domain acme.localhost and I will send a user a password recovery email implementing ShouldQueue with a link inside the mail/notification using the route helper function. The route helper will actually return the route using the root domain (localhost) instead of acme.localhost because of how the routes are setup.

So my question is if there is any elegant way to handle this problem without having to write my own UrlGenerator implementation and instead use a switch task?

@masterix21
Copy link
Collaborator

masterix21 commented Jun 29, 2020

Hi @ivalkenburg,

you need a task to switch your URL. Try with it:

class SwitchRouteUrlTask implements SwitchTenantTask
{
    private $originalUrl;

    public function makeCurrent(Tenant $tenant): void
    {
        $this->originalUrl = config('app.url');

        $protocol = Str::before($this->originalUrl, '://');

        Config::set('app.url', "{$protocol}://{$tenant->domain}");
        URL::forceRootUrl(config('app.url'));
    }

    public function forgetCurrent(): void
    {
        Config::set('app.url', $this->originalUrl);
        URL::forceRootUrl($this->originalUrl);
    }
}

@ivalkenburg
Copy link
Author

Thanks, this seems to work great.

@masterix21
Copy link
Collaborator

@ivalkenburg ok, if the problem has been solved, please close the issue. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants