【发布时间】:2017-12-24 18:59:21
【问题描述】:
我的 RedirectifAuthenticated 中间件中有以下内容:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('dashboard');
}
return $next($request);
}
但是当用户登录时,这是重定向到 /home,我将其重命名为 /dashboard。
我已将路线、视图等从主页更改为仪表板。
我已经对整个项目进行了搜索,但我找不到通往 /home 的路线,也找不到不是标题或无关文件(例如 yarn.lock 文件)中提到的 home。
我找到了很多关于这个问题的文章,但我没有 Authenticate.php 不是我有旧的 Auth 中间件。
编辑:下面是我的登录控制器和路由:
登录控制器:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
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 = '/dashboard';
public function authenticated(Request $request)
{
// Logic that determines where to send the user
if($request->user()->hasRole('Stallhollder')){
return redirect('/dashboard');
}
if($request->user()->hasRole('Manager')){
return redirect('/dashboard2');
}
}
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
路线:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/dashboard', 'DashboardController@index');
Route::resource('/bookings', 'BookingsController');
Route::get('/dashboard2', function () {
return view('dashboard2');
});
【问题讨论】:
-
你能发布你的
LoginController吗?也许还有RedirectIfAuthenticated中间件 -
@Luke.... 请发布您的
Routes Code... 和View文件 -
@ka_lin 对不起,我的电线被越过了
-
@MatthewDaly:没有问题 :) 编码愉快
-
当你调用仪表板时..in url
Route::get('/dashboard', 'DashboardController@index');它转到index页面和index页面重定向到主页。
标签: php laravel laravel-5.4