对于我的网络应用,我们为每个帐户account1.example.org & account2.example.org
设置了子域名。他们都去了同一个地方只是它允许我们在URL中拥有帐户。
我有一切与子域一起工作。我的问题是Laravel 5登录代码。我不确定如何让它重定向到子域(存储在数据库中,可由Auth :: user() - > account-> sub_domain访问)。
我看到人们尝试更改操作但不添加到地址。这样做的最佳方式是什么?
答案 0 :(得分:3)
定义route
-
Route::get(['domain' => '{account}.myapp.com'], function($account){
// Process data or redirect
});
登录后 -
Redirect::to('account1.myapp.com');
答案 1 :(得分:1)
所以在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'
。