https://laravel.com/docs/5.3/authentication#authentication-quickstart
它说
如果重定向路径需要自定义生成逻辑,则可以定义redirectTo方法而不是redirectTo属性
但是我在LoginController中添加了一个redirectTo方法,它没有用!!
仍然重定向到'/ home'!!!
<?php
namespace App\Http\Controllers\Mass\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
// protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
// public function index()
// {
// return \Auth::user();
// }
protected function redirectTo()
{
//
die(var_dump(1));
}
}
答案 0 :(得分:0)
同样的事情发生在我这里,我的代码
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Log;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
protected $redirectTo = '/myaccount';
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
protected function redirectTo()
{
Log::info('redirecthere');
}
}