我已在应用程序中实现了多重身份验证,除管理员注销外,其他一切工作正常。我正在尝试使用exception()方法保护admin.logout路由,但是它不起作用,执行来宾中间件并将其重定向到仪表板。看到路由列表,并且admin.logout路由仍然有guest:admin中间件。我正在尝试从AdminLoginController中的adminLogout方法控制器功能注销admin,但未注销admin。这是我的代码的图片。那么如何解决此管理员注销问题?
auth.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'admin-api' => [
'driver' => 'token',
'provider' => 'admins',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
]
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
];
Web.php
//login routes for users
Route::get('/login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('/login', 'Auth\LoginController@login');
Route::post('/logout', 'Auth\LoginController@logout')->name('logout');
// routes for admin
Route::prefix('admin')->namespace('Admin')->group(function () {
Route::get('login', 'Auth\AdminLoginController@showLoginForm')->name('admin.login');
Route::post('login', 'Auth\AdminLoginController@adminLogin');
Route::post('logout', 'Auth\AdminLoginController@adminLogout')->name('adminlogout');
Route::post('hello', 'Auth\AdminLoginController@hello')->name('adminHello');
Route::group(['middleware' => ['role:admin']], function(){
Route::get('setting', 'AdminController@adminSetting');
Route::get('dashboard', 'AdminController@adminDashboard')->name('admin.dashboard');
Route::get('customers', 'AdminController@customers');
});
});
AdminLoginController.php
<?php
namespace App\Http\Controllers\Admin\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Spatie\Permission\Models\Role;
use App\Admin;
class AdminLoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/home';
public function __construct()
{
$this->middleware('guest:admin')->except('adminlogout');
}
public function showLoginForm(){
return view('auth.admin.adminLogin');
}
public function adminLogin(Request $request)
{
$this->validate($request, [
'email' => 'required|email|exists:admins',
'password' => 'required|min:6'
]);
if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->get('remember'))) {
$request->session()->regenerate();
return redirect()->intended('/admin/dashboard');
}
return back()->withInput($request->only('email', 'remember'));
}
public function adminLogout(Request $request)
{
Auth::guard('admin')->logout();
$request->session()->invalidate();
return redirect('/admin/login');
}
}
当我使用 php artisan route:list 查看所有路线列表时,正在向我显示
admin / logout 路由仍然具有guest:admin中间件,并且它并没有保护我的admin / logout路由不受guest:admin中间件的影响,并没有执行 RedirectIfAuthenticated 中间件,即使我把这个在AdminLoginController中的except()方法中进行路由。 请解决如何从管理员注销?