Laravel Auth中间件不适用于POST路由

I have a simple form in my site and I want to check if the user is currently logged in before he can post the form. I have put auth middleware in the post route...

Route::post('test','SellController@test_mid')->middleware('auth');

My auth middleware...

<?php

public function handle($request, Closure $next, $guard = null)
{
    if (Auth::guard($guard)->guest()) {
        if ($request->ajax() || $request->wantsJson()) {
            return response('Unauthorized.', 401);
        } else {
            return redirect()->guest('login');
        }
    }

    return $next($request);
}

Here 'login' redirects to my login page.

The problem is after I hit the login button, the error is...

MethodNotAllowedHttpException in RouteCollection.php line 219: at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 206

Form...

{{ Form::open(array('url'=>"/test")) }}=
    <input type="submit" value="submit">
{{ Form::close() }}

But if I set the auth middleware on a GET route, it works fine. In case of a GET, if I am logged out, it leads me to the login page. After I provide login credentials and hit the login button it leads me to the desired GET route.

Make sure your view form uses POST method.

{{Form::open(array('url'=>'/test', 'method'=>'post'))}}

Please note that $guard variable is NULL by default unless specified. See your /config/auth.php configuration for available guards.

Route::post('test', 'SellController@test_mid')->middleware('auth:web'); 

I know this question is an old story, but it seems that you have not the answer yet. I suggest using middleware inside your controller instead of routes.

<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;

class YourController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth');
    }

    public function yourFunction(Request $request){
      // your action
    }
}

It works fine for me, either GET or POST method.