Laravel 5.4认证后重定向 [英] Laravel 5.4 Redirect after authentication
问题描述
我的RedirectifAuthenticated中间件中有以下内容:
I have the following in my RedirectifAuthenticated middleware:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('dashboard');
}
return $next($request);
}
但是,当用户登录时,这将重定向到我更名为/dashboard的/home.
But when a user logs in, this is redirecting to /home which I renamed to /dashboard.
我已将路线,视图等从家更改为仪表板.
I have changed the routes, views etc from home to dashboard.
我已经在整个项目中进行了搜索,但找不到到/home的路线,也没有找到不是标题或不相关的文件(例如yarn.lock文件)的提及之家.
I have run a search throughout the whole projects and I cannot find a route to /home or a mention of home that is not the title or in unrelated filed such as the yarn.lock file.
我找到了很多有关此问题的文章,但是我没有Authenticate.php,也没有旧的Auth中间件.
I have found many articles on this issue but I do not have an Authenticate.php not do I have the old Auth middleware.
以下是我的登录控制器和路线:
Below are my Login Controller and routes:
LoginController:
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
{
/*
|--------------------------------------------------------------------------
| 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');
});
推荐答案
默认的Laravel登录控制器将$redirectTo
的值设置为"/home".您需要将其更新为新路由,以定义登录后重定向到的新路由.
The default Laravel login controller sets the value of $redirectTo
to '/home'. You need to update that to the new route as that defines where it gets redirected to after login.
这篇关于Laravel 5.4认证后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!