![](/img/trans.png)
[英]redirect user to specific page after he register its no working, the user is being redirected to the homepage
[英]Why the user is redirected to the login page instead of homepage when he clicks in the logo link?
當用戶單擊“登錄”鏈接時,用戶將轉到頁面“ http://project.test/login ”。 如果我單擊此鏈接中的徽標,則在此頁面中:
<a href="{{route('home')}}">LOGO</a>
用戶應轉到主頁“ http://project.test/ ”,但用戶仍留在頁面“ http://project.test/login ”中。
你知道為什么嗎?
的LoginController:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/home';
public function __construct()
{
$this->middleware('guest')->except('logout');
}
protected function authenticated(Request $request, $user)
{
return redirect()->intended($this->redirectTo);
}
}
路線:
Auth::routes();
Route::get('auth/{provider}', [
'uses' => 'OauthController@redirectToProvider',
'as' => 'social.auth'
]);
Route::get('auth/{provider}/callback', [
'uses' => 'OauthController@handleProviderCallback',
]);
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/', [
'uses' => 'FrontController@index',
'as' =>'index'
]);
將徽標的鏈接從<a href="{{route('home')}}">LOGO</a>
更改為<a href="{{ url('/home') }}">LOGO</a>
。 不要更改任何其他內容,只要保持原樣即可。
希望能幫助到你。
您是否嘗試過將路線設置為
Route::get('/', 'HomeController@index')->name('home');
您是否嘗試添加或更改路線,例如
Route::get('/', 'HomeController@index')->name('home');
在您看來如此簡單
<a href="{{route('home')}}">LOGO</a>
如果您的用戶是登錄用戶,請不要忘記在Routes上使用返回值,並在中間件中定義返回值(如果您使用的是Laravel 5.X)
嘗試這個
protected function authenticated(Request $request, $user)
{
if ( $user->isAdmin() ) {// do your margic here
return redirect()->route('dashboard');
}
return redirect('/home');
}
如討論末尾的評論中所述,替換
<a href="{{route('home')}}">LOGO</a>
同
<a href="{{route('index')}}">LOGO</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.