Laravel 5: POST without CSRF checking

后端 未结 4 925
醉梦人生
醉梦人生 2021-01-17 19:07

It seems that Laravel 5 by default applies the CSRF filter to all non-get requests. This is OK for a form POST, but might be a problem to an API that POSTs DELETEs etc.

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-17 19:16

    Go to app/Http/Middleware/VerifyCsrfToken.php and then enter your routes(for which you want to disable csrf token) in the $except array.

    for example:

    class VerifyCsrfToken extends BaseVerifier
    {
    
        protected $except = [
    
            '/register'
    
        ];
    }
    

提交回复
热议问题