从自定义管理面板Laravel 5.7无法注销

时间:2018-11-03 13:35:01

标签: laravel admin logout laravel-5.7

我喜欢Matrix Admin面板,因此我开始实施它。我不喜欢在用户模型中使用admin(布尔检查isAdmin)的选项,因此我创建了一个单独的模型,称为Admin。我设置了所有路由,并在我的测试管理页面中使用了以下路由:

 web.php

Route::get('/admin/login', 'Auth\AdminLoginController@showLoginForm')- 
 >name('admin.login');
Route::post('/admin/login', 'Auth\AdminLoginController@login')- 
 >name('admin.login.submit');
Route::get('/admin', 'AdminController@index')->name('admin.admin');

This is my AdminLoginController:
 public function showLoginForm()
{
    return view('admin/admin-login');
}
protected function guard(){
    return Auth::guard('admin');
}

use AuthenticatesUsers;

protected $redirectTo = '/admin/login';

 public function __construct()
{
    $this->middleware('guest:admin')->except('logout');
}

And my AdminController:
public function __construct()
{
    $this->middleware('auth:admin');
}

public function index()
{
    return view('admin.admin');
}

I call routes in the view like this:
href="{{ route('admin.login') }}"

For some reason, it doesn't log me out and get me to the login page, instead it just refreshes the page, hence returns me to the /admin page with the admin logged in. What am i missing here? Thanks for all replies.

2 个答案:

答案 0 :(得分:0)

AdminLoginController的构造函数中,您已将中间件设置为'guest:admin'

这使用默认情况下在/app/Http/Middleware/RedirectIfAuthenticated.php中定义或在/app/Http/Kernel.php中配置的来宾中间件

传递给它使用的$guard字符串是'admin'。 我猜您为该 admin 卫队提供了一个实现。

假设您以管理员身份登录,导航至route('admin.login') 将在默认实现中redirect your request to '/home'; 您的实现中很可能存在到/admin的自定义重定向。

如果您想注销会话,则可以为Illuminate\Foundation\Auth\AuthenticatesUsers trait中提供的logout方法注册路由。

Route::get('/admin/logout', 'AdminController@logout')->name('admin.logout');

由于默认情况下AuthenticatesUsers::logout重定向到/,所以我猜测您需要覆盖此行为。 您可以通过在控制器中为AuthenticatesUsers::loggedOut提供自定义实现来做到这一点。

protected function loggedOut(Request $request)
{
    return redirect('/admin');
}

最后,在链接{{ route('admin.logout') }}

中为 href 提供此路由

答案 1 :(得分:0)

与会话有关,

Sub HGScrape()

    Const sURL As String = "https://www.healthgrades.com/"

    Dim ie As New InternetExplorer
    Dim loop_ctr As Integer

    With ie

        .Visible = False
        .Navigate sURL
        While .Busy Or .ReadyState < 4: DoEvents: Wend
        .document.getElementById("search-term-selector-child"). _
                    Value = ActiveSheet.Range("A2")
        .document.getElementById("search-location-selector-child"). _
                    Value = ActiveSheet.Range("B2")
        .document.getElementsByClassName("submiter__text")(0).Click
        While .Busy Or .ReadyState < 4: DoEvents: Wend

        ActiveSheet.Range("C2").Value = .document.getElementsByClassName("uCard__age")(0).innerText
        While .Busy Or .ReadyState < 4: DoEvents: Wend
        ActiveSheet.Range("D2").Value = .document.getElementsByClassName("address--street")(0).innerText
        While .Busy Or .ReadyState < 4: DoEvents: Wend
        ActiveSheet.Range("E2").Value = .document.getElementsByClassName("address--city-state")(0).innerText

        For loop_ctr = 3 To 10

            .document.getElementById("uSearch-search-term-selector-child"). _
                        Value = ActiveSheet.Range("A" & loop_ctr)
            .document.getElementById("uSearch-search-location-selector-child"). _
                        Value = ActiveSheet.Range("B" & loop_ctr)
            .document.getElementsByClassName("submiter__text")(0).Click
            While .Busy Or .ReadyState < 4: DoEvents: Wend

            ActiveSheet.Range("C" & loop_ctr).Value = .document.getElementsByClassName("uCard__age")(0).innerText
            While .Busy Or .ReadyState < 4: DoEvents: Wend
            ActiveSheet.Range("D" & loop_ctr).Value = .document.getElementsByClassName("address--street")(0).innerText
            While .Busy Or .ReadyState < 4: DoEvents: Wend
            ActiveSheet.Range("E" & loop_ctr).Value = .document.getElementsByClassName("address--city-state")(0).innerText
            While .Busy Or .ReadyState < 4: DoEvents: Wend

        Next loop_ctr

    End With

    Set ie = Nothing

End Sub