[英]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.