在laravel 5.5的验证csrf标记中没有得到错误的令牌不匹配异常 [英] not getting the error Token mismatch exception in Verify csrf token in laravel 5.5

查看:748
本文介绍了在laravel 5.5的验证csrf标记中没有得到错误的令牌不匹配异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Laravel的新成员,我使用的是Laravel 5.5。

当我提交时没有 {{csrf_field()}}
在验证csrf标记中未收到错误令牌不匹配异常



错误是

lockquote
<页面由于不活动而已过期。
请刷新并再试一次

我的HTML表单是

 < form method =POSTaction =/ post> 

< div class =form-group>
< label for =title>标题< / label>
< input type =textclass =form-controlname =title>

< / div>

< div class =form-group>
< label for =textblog>正文< / label>
< input type =textareaclass =form-controlname =body>
< / div>

< button type =submitclass =btn btn-primary>发布< /按钮>
< / form>

我的路线网页文件

 路线::交( '/后', 'PostsController @商店'); 

以下是我的Controller类函数

<$ p ()() - > all()); $ p> public function store(){
dd
}


解决方案

https ://es.stackoverflow.com/questions/99342/laravel-5-5-the-page-has-expired-due-to-inactivity-please-refresh-and-try-aga



在Laravel 5.5中,TokenMismatch抛出一个代码为419的异常



更新:..以及包含消息的错误页面该页面已失效,请刷新并重试



我建议安装 https://github.com/barryvdh/laravel-debugbar
所以你可以看到例外情况。



您可能会看到
../ vendor / laravel / framework / src / Illuminate / Foundation / Http / Middleware / VerifyCsrfToken.php#70


  return $ this-> addCookieToResponse($ request,$ n分机($请求)); 
}

抛出新的TokenMismatchException;

更新:


当我在没有{{csrf_field()}}的情况下提交没有在验证csrf标记中得到错误令牌不匹配异常时


你会得到不匹配的异常,但会出现新的错误页面和代码。
https://laravel-news.com/laravel-5 -5-error-views



{{csrf_field()}}创建一个隐藏有令牌的输入,因此您必须在您的表单(也检查表单中的标记是否为空)

 < input type =hiddenname =_ token value =nReVYpjfvqiVVkE8LpGeNOdJZnskNLGoB57YHFkO> 


I am new in Laravel and I am using Laravel 5.5.
When I am submitting without {{ csrf_field() }} not getting the error Token mismatch exception in Verify csrf token

The error is

The page has expired due to inactivity. Please refresh and try again

My HTML form is

<form method="POST" action="/post">

    <div class="form-group">
        <label for="title">Title</label>
        <input type="text" class="form-control" name="title">

    </div>

    <div class="form-group">
        <label for="textblog">Body</label>
        <input type="textarea" class="form-control" name="body">
    </div>

    <button type="submit" class="btn btn-primary">Publish</button>
</form>

My Route web file

Route::post('/post','PostsController@store');

Here is my Controller class function

public function store() {
    dd(request()->all());
}

解决方案

As @Shaz said in https://es.stackoverflow.com/questions/99342/laravel-5-5-the-page-has-expired-due-to-inactivity-please-refresh-and-try-aga

In Laravel 5.5, "TokenMismatch" throws an exception with code 419

Update: .. and an error page with the message "The page has expired due to inactivity. Please refresh and try again"

I would recommend installing https://github.com/barryvdh/laravel-debugbar so you can see the exceptions.

You will probably see ../vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php#70

 return $this->addCookieToResponse($request, $next($request));
    }

    throw new TokenMismatchException;
}

Update:

When I am submitting without {{ csrf_field() }} not getting the error Token mismatch exception in Verify csrf token

You are getting the mismatch exception but with the new error page and code. (https://laravel-news.com/laravel-5-5-error-views)

The {{ csrf_field() }} creates an input hidden with the token, so you have to use it in your forms ( also check that the token is not empty in the form )

<input type="hidden" name="_token" value="nReVYpjfvqiVVkE8LpGeNOdJZnskNLGoB57YHFkO">

这篇关于在laravel 5.5的验证csrf标记中没有得到错误的令牌不匹配异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆