当我在视图中使用$errors时,laravel会报错,提醒$errors未定义,服务器端环境为homestead4.0.0,laravel版本为5.2。
我看5.2手册中说明$errors在每个视图中均可用啊,请问这是怎么一回事啊?
当我在视图中使用$errors时,laravel会报错,提醒$errors未定义,服务器端环境为homestead4.0.0,laravel版本为5.2。
我看5.2手册中说明$errors在每个视图中均可用啊,请问这是怎么一回事啊?
问题解决了,虽然不是@rainwsy和@hi两位说的问题,但是很感谢回答。
造成这个问题的原因是5.2源码改动,但是手册里面又没有写清楚,或者我没有看清楚,现将解决办法贴下来,供有相同需求的朋友一览:
This is a breaking problem with the 5.2 upgrade. What's happening is the middleware which is responsible for making that errors variable available to all your views is not being utilized because it was moved from the global middleware to the web middleware group. There are two ways to fix this: In your kernel.php file, you can move the middleware \Illuminate\View\Middleware\ShareErrorsFromSession::class back to the protected $middleware property. You can wrap all your web routes with a route group and apply the web middleware to them. Route::group(['middleware' => 'web'], function() { // Place all your web routes here... });
原文地址:Laravel 5.2 $errors not appearing in Blade
你要判断有错误才输出显示
在线证件照系统是一套完善的冲印行业解决方案,致力于解决用户线上拍摄证件照,拍摄最美最标准证件照的使命。证件照免费版功能:后台统计:当天制作、当天新增、支持规格、近7日统计规格列表:筛选查看、编辑用户列表:筛选查看常见问题:筛选查看、新增、编辑、删除小程序设置:应用设置、流量主设置小程序跳转:筛选查看、新增、编辑、删除关注公众号:引导设置系统要求:系统:Linux系统(centos x64)运行环境
1
<code>@if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br>
<br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif</code>
https://laravel.com/docs/5.2/quickstart-intermediate#validation
The $errors Variable
是不是还要引入一个通用文件 @include('common.errors')
楼主解决得不错,赞一个
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号