Laravel 5.2 logout()不起作用

时间:2016-09-18 18:26:48

标签: laravel laravel-5 laravel-5.2 laravel-routing

当我使用make:auth on命令创建简单的授权页面时,我可以登录并注册成功,但是当我尝试点击logout我得到错误时,我使用了最新的upadte laravel 5.2,这是我的AuthController

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Validator;

class AuthController extends Controller
{
    use AuthenticatesAndRegistersUsers, ThrottlesLogins;
    protected $redirectTo = '/home';

    public function __construct()
    {
        $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
    }

    protected function validator(array $data)
    {
        return Validator::make($data, [
            //@formatter:off
                'username'      => 'required|max:255',
                'name'          => 'required|max:255',
                'email'         => 'required|email|max:255|unique:users',
                'password'      => 'required|min:6|confirmed',
            //@formatter:on
        ]);
    }

    public function getLogout()
    {
            auth()->logout();

            return redirect()->route('/home');
    }  

    protected function create(array $data)
    {
        return User::create([
            //@formatter:off
            'username'  => $data['username'],
            'name'      => $data['name'],
            'email'     => $data['email'],
            'password'  => bcrypt($data['password']),
            //@formatter:on
        ]);
    }
}

我阅读了越来越多有这个问题的主题,但解决方案无法解决我的问题,如添加

Route::get('auth/logout', 'Auth\AuthController@logout');

在路线上或使用middleware上的constructor

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

我在布局上注销的链接是:

<li><a href="{{ url('/auth/logout') }}"><i class="fa fa-btn fa-sign-out"></i>Logout</a></li>

我收到此错误:

NotFoundHttpException in compiled.php line 8912:

完整堆栈错误:

in compiled.php line 8912
at RouteCollection->match(object(Request)) in compiled.php line 8264
at Router->findRoute(object(Request)) in compiled.php line 8212
at Router->dispatchToRoute(object(Request)) in compiled.php line 8207
at Router->dispatch(object(Request)) in compiled.php line 2419
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 3286
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9963
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in compiled.php line 9948
at Pipeline->then(object(Closure)) in compiled.php line 2366
at Kernel->sendRequestThroughRouter(object(Request)) in compiled.php line 2350
at Kernel->handle(object(Request)) in index.php line 54

2 个答案:

答案 0 :(得分:0)

看来,你的路由是缓存,所以你应该尝试:

php artisan route:clear

清除路由缓存

php artisan route:cache

清除缓存并创建新的路由缓存

答案 1 :(得分:0)

尝试注销

Session::flush();
Auth::logout();
Cache::flush();
return Redirect::to('/home');

希望这能解决您的问题。