繁体   English   中英

Laravel 5登录重定向到子域

[英]Laravel 5 Login redirect to a subdomain

对于我的Web应用程序,每个帐户都有一个子域account1.example.org & account2.example.org 他们都去了同一个地方,只是它允许我们在URL中拥有该帐户。

我可以使用所有子域。 我的问题是Laravel 5登录代码。 我不确定如何重定向到子域(存储在数据库中,并且可以通过Auth :: user()-> account-> sub_domain访问)。

我见过人们尝试更改操作,但未添加到地址中。 做这个的最好方式是什么?

定义route -

Route::get(['domain' => '{account}.myapp.com'], function($account){
    // Process data or redirect
});

登录后-

Redirect::to('account1.myapp.com');

因此,在sgt BOSE的帮助下,这就是我想到的。

在我的AuthController.php我添加了

/**
 * Redirect Path
 *
 * @return \Illuminate\Http\RedirectResponse
 */
public function redirectPath()
{
    $redirectTo = property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';

    $url = Config::get('app.url');
    $subDomain = Auth::user()->account->sub_domain;
    $scheme = parse_url($url, PHP_URL_SCHEME);
    $host = parse_url($url, PHP_URL_HOST);
    return $scheme.'://'.$subDomain.'.'.$host.$redirectTo;
}

这是返回postLogin和postRegister的链接。 仅在成功时才调用此方法。 获取我的子域,并基于URL的配置项构建链接。

为了确保登录有效,我还必须更改config/session.php文件中的域项目。 'domain' => null -> 'domain' => '.example.org'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM