2017-01-07 83 views
0

我正在使用Laravel 5.3.29。我想爲身份驗證創建自定義路由。Laravel Auth自定義路由重定向到/ login登錄/(自定義路徑)/登錄

這是我的網路代碼。

Route::group(['prefix' => 'hrs'], function(){ Auth::routes(); }); 
Route::get('/', function() { return view('welcome'); }); 
Route::get('/home', '[email protected]'); 

我做了所有資源代碼從/ home到/ hrs/home和其他的所有資源代碼。

這是我的HomeController代碼:

public function __construct() 
{ $this->middleware('auth'); } 
public function index() 
{ return view('home'); } 

的問題時,我打本地主機/回家時,我不是在登錄發生它重定向我到localhost /登錄,而不是本地主機/小時/登錄。 redirect error pic

在哪裏必須更改重定向到localhost/hrs/login。

回答

2

除了一件事情你做得很好。您尚未將Handler.php文件更改爲app\Exceptions\目錄。只要改變成Handler.php文件到unauthenticated()方法是這樣的:)

回報重定向( - >客( '小時/登錄');

全碼:

protected function unauthenticated($request, AuthenticationException $exception) 
{ 
    if ($request->expectsJson()) { 
     return response()->json(['error' => 'Unauthenticated.'], 401); 
    } 

    return redirect()->guest('hrs/login'); 
} 
+1

完美的作品。非常感謝你。 –