首页 / PHP / Laravel5表单验证问题
Laravel5表单验证问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Laravel5表单验证问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2955字,纯文字阅读大概需要5分钟。
内容图文
![Laravel5表单验证问题](/upload/InfoBanner/zyjiaocheng/240/ea8a4d678c9341dca047e4511f7b8f32.jpg)
为什么设置了表单验证的attributes仍然不显示其设定的值?
如图所示:
设置了
$attributes = array(
"title" => '标题',
'content' => '正文'
);
提示仍然是title 不能小于10个字
而不是标题 不能小于10个字
有用过的大神知道是怎么回事没。
貌似图片挂了,截图:http://7xjkan.com1.z0.glb.clouddn.com/QQ%E5%9B%BE%E7%89%8720151026170220.png
controller:
public function update(Request $request,$id)
{
$rules = array(
'title' => 'required|max:255|min:10',
'content' => 'required|min:50|max:20000',
);
$message = array(
"title.required"=> ":attribute 不能为空",
"title.min"=> ":attribute 不能小于10个字",
"title.max"=> ":attribute 不能超过50个字",
"content.required"=>":attribute 不能为空",
"content.min"=>":attribute 不能小于50个字",
"content.max"=>":attribute 不能超过20000个字"
);
$attributes = array(
"title" => '标题',
'content' => '正文'
);
/*$this->validate($request, [
'title' => 'required|max:255|min:5',
'content' => 'required',
]);*/
$this->validate($request,$rules,$message,$attributes);
$article = Article::find($id);
$article->title = \Input::get('title');
$article->content = \Input::get('content');
if ($article->save()) {
return \Redirect::to('article');
} else {
return \Redirect::back()->withInput()->withErrors('保存失败!');
}
}
视图:
@extends('app')
@section('content')
Article
@if (count($errors) > 0)
Whoops! There were some problems with your input.
@foreach ($errors->all() as $error)
- {{ $error }}
@endforeach
@endif
@stop
回复内容:
为什么设置了表单验证的attributes仍然不显示其设定的值?
如图所示:
设置了
$attributes = array(
"title" => '标题',
'content' => '正文'
);
提示仍然是title 不能小于10个字
而不是标题 不能小于10个字
有用过的大神知道是怎么回事没。
貌似图片挂了,截图:http://7xjkan.com1.z0.glb.clouddn.com/QQ%E5%9B%BE%E7%89%8720151026170220.png
controller:
public function update(Request $request,$id)
{
$rules = array(
'title' => 'required|max:255|min:10',
'content' => 'required|min:50|max:20000',
);
$message = array(
"title.required"=> ":attribute 不能为空",
"title.min"=> ":attribute 不能小于10个字",
"title.max"=> ":attribute 不能超过50个字",
"content.required"=>":attribute 不能为空",
"content.min"=>":attribute 不能小于50个字",
"content.max"=>":attribute 不能超过20000个字"
);
$attributes = array(
"title" => '标题',
'content' => '正文'
);
/*$this->validate($request, [
'title' => 'required|max:255|min:5',
'content' => 'required',
]);*/
$this->validate($request,$rules,$message,$attributes);
$article = Article::find($id);
$article->title = \Input::get('title');
$article->content = \Input::get('content');
if ($article->save()) {
return \Redirect::to('article');
} else {
return \Redirect::back()->withInput()->withErrors('保存失败!');
}
}
视图:
@extends('app')
@section('content')
Article
@if (count($errors) > 0)
Whoops! There were some problems with your input.
@foreach ($errors->all() as $error)
- {{ $error }}
@endforeach
@endif
@stop
'custom' => [
'title' => [
'required' => '标题不能为空',
],
],
找到resources/lang/en/validation.php
中的custome,这个满足你的要求不?更多的Laravel 5教程:
https://laravist.com/series/laravel-5-basic
内容总结
以上是互联网集市为您收集整理的Laravel5表单验证问题全部内容,希望文章能够帮你解决Laravel5表单验证问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。