2017-09-02 80 views
0

我的laravel版本是5.0.35,我的问题是当我注销时,它会重定向回主页。Laravel 5.0注销重定向回到主页

经过数小时的自我研究和谷歌搜索,我经历了许多决议,但没有工作。 例如:$ this-> middleware('guest',['except'=> ['logout','getLogout']]);

由于某种原因,访客中间件正在将请求重定向回主页,不知道为什么即使添加注销方法时也会免除注销方法。 任何人都请帮我解决这个问题。

我AuthController现在

<?php namespace App\Http\Controllers\Auth; 

use App\Http\Controllers\Controller; 
use Illuminate\Contracts\Auth\Guard; 
use Illuminate\Contracts\Auth\Registrar; 
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; 

use Illuminate\Http\Request; 
use Illuminate\Support\Facades\Auth; 

class AuthController extends Controller { 

    /* 
    |-------------------------------------------------------------------------- 
    | Registration & Login Controller 
    |-------------------------------------------------------------------------- 
    | 
    | This controller handles the registration of new users, as well as the 
    | authentication of existing users. By default, this controller uses 
    | a simple trait to add these behaviors. Why don't you explore it? 
    | 
    */ 

    use AuthenticatesAndRegistersUsers; 

    /** 
    * Create a new authentication controller instance. 
    * 
    * @param \Illuminate\Contracts\Auth\Guard $auth 
    * @param \Illuminate\Contracts\Auth\Registrar $registrar 
    * @return void 
    */ 
    public function __construct(Guard $auth, Registrar $registrar) 
    { 
     $this->auth = $auth; 
     $this->registrar = $registrar; 

     $this->middleware('guest', ['except' => 'logout']); 
    } 

    public function logout(Request $request) 
    { 
     $this->guard()->logout(); 

     $request->session()->invalidate(); 

     return redirect('/'); //****** Change to your desired link. 
    } 
} 

我有一个希望的项目升级到5.1.0来解决问题,但还是没有用。 任何人都请帮忙。

+0

你怎么想呢? – shigg

回答

1

修改此:

<?php 

namespace App\Http\Controllers\Auth; 

use App\Http\Controllers\Controller; 
use Illuminate\Contracts\Auth\Guard; 
use Illuminate\Contracts\Auth\Registrar; 
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; 


class AuthController extends Controller { 

    /* 
    |-------------------------------------------------------------------------- 
    | Registration & Login Controller 
    |-------------------------------------------------------------------------- 
    | 
    | This controller handles the registration of new users, as well as the 
    | authentication of existing users. By default, this controller uses 
    | a simple trait to add these behaviors. Why don't you explore it? 
    | 
    */ 

    use AuthenticatesAndRegistersUsers; 

    /** 
    * Create a new authentication controller instance. 
    * 
    * @param \Illuminate\Contracts\Auth\Guard $auth 
    * @param \Illuminate\Contracts\Auth\Registrar $registrar 
    * @return void 
    */ 
    public function __construct(Guard $auth, Registrar $registrar) 
    { 
     $this->auth = $auth; 
     $this->registrar = $registrar; 

     $this->middleware('guest', ['except' => ['logout', 'getLogout']]); 
    } 

    public function getLogout() 
    { 
     $this->auth->logout(); 
     return redirect('/mypage'); //**your link 
    } 
} 
+0

我没有LoginController那里,这是版本5.0.35。如果你的意思是AuthController,我通过添加这些来检查,但没有奏效。 – manugdas

+0

显示您的控制器。 –

+0

我已经用我的authcontroller更新了这个问题,包括你给我的方法。请检查。 – manugdas