尝试验证中间件时,Laravel 5.5中止错误

时间:2017-11-12 21:17:55

标签: php laravel

当我尝试登录我的仪表板时,我的身份验证在没有中间件的情况下运行良好,但是当我应用中间件并尝试登录仪表板时,我得到了这个。

enter image description here

这与我的身份验证中间件文件

相关联

中间件/ Authenticate.php

<?php

namespace App\Http\Middleware;

use Closure;

use Illuminate\Support\Facades\Auth;

class Authenticate
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(! Auth::User()) {
            if ($request->expectsJson()) {
                return response()->json(['error' => 'Unauthenticated. You are not a User.'], 401);
            }

            abort(403, "You're not a User no permission bro");
        }

        return $next($request);
    }
}

我的路线之后是:

Route::get('/auth/signup','UserController@getRegister')->name('getRegister');

Route::post('/auth/signup', 'UserController@userRegister')->name('signup');

Route::post('/auth/signin','UserController@userLogin')->name('user.login');


Route::get('/auth/login', 'UserController@getLogin')->name('login');
Route::get('/', 'UserController@getHome')->name('home');
Route::get('/auth/logout', 'UserController@logOut')->name('logout');


Route::group(['middleware' => 'myauth'], function() {

    Route::get('/dashboard', 'UserController@getDashboard')->name('dashboard');

});

提前感谢我开始认为存在错误,因为我正在遵循laravel 5.5惯例。

0 个答案:

没有答案