Laravel中发生注销错误

时间:2018-02-23 03:49:04

标签: php laravel laravel-5

我试图退出,但收到错误

  

ReflectionException(-1)Class App \ Http \ Controllers \ LoginController   不存在

我在LoginController中添加了注销方法,但它不起作用

LoginController.php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller {

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct() {
        $this->middleware('guest')->except('logout');
    }

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

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

        return redirect('/index');
    }

}

Blade.php文件

<ul id="dropdown1" class="dropdown-content">
    <li><a href="#!">Parametres</a></li>
    <li><a href="/logout">Deonnexion</a></li> 
</ul>

路线

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');
Route::get('/logout', 'LoginController@logout');

2 个答案:

答案 0 :(得分:2)

添加

后终于工作了
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; 

到LoginController.php文件

答案 1 :(得分:0)

您是否检查过命名空间?
命名空间App \ Http \ Controllers;

https://laravel.com/docs/5.1/controllers