Laravel wrong domain in reset password link

寵の児 提交于 2019-12-24 10:49:42

问题


I'm getting a bad URL generated by sendResetLinkResponse controller in laravel 5.8 having the domain twice.

https://api.domain.org/domain.org/password/reset/....

But it should be

https://api.domain.org/password/reset/....

The APP_URL is set to

APP_URL=domain.org

I use a custom config to be able to have as endpoint api.domain.org instead of www.domain.org/api

My configuration is:

protected function mapApiRoutes() {

 Route::domain('api.' .  env('APP_URL'))
   ->middleware('api')
   ->namespace($this->namespace)
   ->group(base_path('routes/api.php'));
}

How can I fix it?


回答1:


I would suggest setting up your subdomain to be more dynamic i.e.

Route::domain('api.{domain}')
    ->middleware(['api', function ($request, $next) {
        $request->route()->forgetParameter('domain');

        return $next($request);
    }])
    ->namespace($this->namespace)
    ->group(base_path('routes/api.php'));

The above basically allows for any domain name and then the middleware just removes it from your route params so that it doesn't mess with your route closures or controller methods.

You will also need to add the following to the boot method of your service provider:

Route::pattern('domain', '[a-z0-9.]+');

This way you can use the APP_URL to just be the domain for the site.



来源:https://stackoverflow.com/questions/57073662/laravel-wrong-domain-in-reset-password-link

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!