laravel - Laravel 并在占位符中显示错误
问题描述
我有一个关于在 laravel 中显示错误的问题。所以我希望错误显示在占位符中。我已经做到了,但是,还有另一个问题。当我打开页面时,我看不到占位符,因此用户无法获取名称和姓氏等的输入。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="{{asset('css/signup.css')}}">
</head>
<body>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Login</title>
</head>
<body>
<div class="container">
<div class="logo"></div>
<form action="{{url('/register')}}" method='post'>
{{csrf_field()}}
<input name='name' id='name'value='@if(!$errors->first("name")){{old("name")}}@endif' placeholder="{{$errors->first('name')}}">
<input name='surname' value='@if(!$errors->first("surname")){{old("surname")}}@endif' placeholder="{{$errors->first('surname')}}">
<input name='email' value='@if(!$errors->first("email")){{old("email")}}@endif' placeholder="{{$errors->first('email')}}">
<input name='age' value='@if(!$errors->first("age")){{old("age")}}@endif' placeholder="{{$errors->first('age')}}">
<input name='password' value='@if(!$errors->first("password")){{old("password")}}@endif' type='password' placeholder='{{$errors->first("password")}}'>
<input name='confirm' value='@if(!$errors->first("confirm")){{old("confirm")}}@endif' type='password' placeholder='{{$errors->first("confirm")}}'>
<button class='btn btn-danger'>Save</button>
</form>
</div>
</body>
</html>
</body>
</html>
解决方案
更新
<input name='name' id='name'value='@if(!$errors->first("name")){{old("name")}}@endif' placeholder="{{$errors->first('name')}}">
至
<input name='name' id='name'value='@if(!$errors->first("name")){{old("name")}}@endif' placeholder="{{$errors->has('name') ? $errors->first('name') : 'Name' }}">
其他输入标签的更新方式也相同。
推荐阅读
- ruby-on-rails - 根据过去的一个月 ruby on rails 6 创建整个月的记录,每个月
- mongodb - mongodb命令行二十结果限制让我发疯
- java - 拆分为方法的最佳实践
- ms-word - 如何自定义(更改)MS Word 跟踪更改“插入”和“删除”的颜色设置
- ssis - 具有行计数条件拆分的 SSIS 查询写入 0 行
- javascript - 禁用 WebRTC 跟踪会停止消耗带宽吗?
- reactjs - 如何在材料表中创建 onHover 动作?
- excel - 无法在 MacOS Catalina 中安装 Excel Desktop 的任何加载项(Microsoft Excel 无法访问该文件)
- javascript - 如何使用浏览器控制台将受保护的 Google Drive pdf 下载为 .jpg 图像?
- django - 如何刷新管理表单上的外键下拉列表