laravel - “页面已过期错误 419” - Laravel 7
问题描述
我的注册页面正在正确显示表单,其中 CsrfToken ({{ csrf_field() }}) 出现在表单中。
<form method="post" action="{{route('products.store')}}">
{{csrf_field()}}
{{ method_field('post') }}
<div class="form-group">
<label for="exampleName">Name</label>
<input type="text" class="form-control" name="name" id="exampleName" placeholder="Enter Name" aria-describedby="emailHelp">
</div>
<div class="form-group">
<label for="exampleDescription">Description</label>
<input type="text" class="form-control" name="desc" id="exampleDescription" placeholder="Enter Name" aria-describedby="emailHelp">
</div>
<div class="form-group">
<label for="exampleWeight">Weight</label>
<input type="text" class="form-control" name="weight" id="exampleWeight" aria-describedby="emailHelp">
</div>
<div class="form-group">
<label for="examplePrice">Price</label>
<input type="text" class="form-control" name="price" id="examplePrice" aria-describedby="emailHelp">
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
当我提交表单时(也刚刚重新加载),它给出了页面已过期,由于错误 419。请刷新并重试。错误。
我非常尝试但无法解决
请帮助我,非常感谢
解决方案
本文可能对您有所帮助: https ://medium.com/@tiwarishani/how-to-solve-the-page-expired-419-error-in-laravel-69fd97b0aa71
1. 你在生产吗?使用https?我有同样的问题,不是 CSRF 令牌。所以我为此更改了 AppServiceProvider.php boot() 方法(在我的例子中之前是空的):
public function boot(UrlGenerator $url)
{
Schema::defaultStringLength(191);
if (env('APP_ENV') !== 'local') {
$url->forceScheme('https');
}
}
不要忘记顶部的这一行:
use Illuminate\Routing\UrlGenerator;
** 关于在配置文件之外使用 env(),请务必执行
php artisan config:clear
测试前
2.您需要对 storage/framework/sessions 文件夹(755)执行写入权限
chmod 755 storage/framework/sessions
chmod 755 bootstrap/cache
chmod 644 vendor (not very sure about this)
SESSION_DOMAIN 环境变量可能很重要。
推荐阅读
- java - Clob 到字符串的转换
- reactjs - 直接从带有 CORS 异常的应用程序错误中调用 kubernetes api
- javascript - 如何在 eko studio 代码编辑器中添加基于浏览器的节点
- typescript - 在 VSCode / Typescript 项目上以编程方式调用“组织导入”
- python - 如何识别图像中具有相似强度的附近像素?
- reactjs - 如何优化大量子组件的重渲染?
- angular - 无法通过单击在 Angular 中选择单选按钮
- antlr4 - ANTLR 匹配错误的标记
- vba - 在电子邮件正文中使用 Excel VBA IF THEN 语句
- c - 在c中使用递归函数的寻路程序