当我尝试登录我的仪表板时,我的身份验证在没有中间件的情况下运行良好,但是当我应用中间件并尝试登录仪表板时,我得到了这个。
这与我的身份验证中间件文件
相关联中间件/ 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惯例。