Laravel old()无法正常工作 [英] Laravel old() not working
本文介绍了Laravel old()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{!! Form::open(array('route' => 'posts.store', 'data-parsley-validate' => '')) !!}
{{ Form::label('title', 'Title:') }}
{{ Form::text('title',old('title'), array('class' => 'form-control', 'required' => '', 'maxlength' => '255')) }}
{{ Form::label('slug', 'Slug:') }}
{{ Form::text('slug',old('slug'), array('class' => 'form-control', 'required' => '', 'minlength' => '5', 'maxlength' => '255') ) }}
{{ Form::label('category_id', 'Category:') }}
<select class="form-control" name="category_id">
@foreach($categories as $key=>$value)
<option value='{{ $key }}'>{{ $value }}</option>
@endforeach
</select>
{{ Form::label('tags', 'Tags:') }}
<select class="form-control select2-multi" name="tags[]" multiple="multiple">
@foreach($tags as $tag)
<option value='{{ $tag->id }}'>{{ $tag->name }}</option>
@endforeach
</select>
{{ Form::label('body', "Post Body:") }}
{{ Form::textarea('body',old('body'), array('class' => 'form-control','id'=>'editor1')) }}
{{ Form::submit('Create Post', array('class' => 'btn btn-success btn-lg btn-block', 'style' => 'margin-top: 20px;')) }}
{!! Form::close() !!}
这是我的表单,但是当我提交它并在服务器端对其进行验证并重定向到同一页面时,它不会显示旧值.
This is my form for something but however when i submit it and validate it on the server side and redirect to the same page , it doesn't display the old values.
控制器端
$this->validate($request,[
'title'=>'required|max:255',
'body'=>'required',
'slug'=>'required|max:255|alpha_dash|min:5|unique:posts,slug',
'category_id'=>'required|integer'
]);
$post=new Post;
$post->title=$request->title;
$post->slug=$request->slug;
$post->body=$request->body;
$dom = new Dom;
$dom->load($request->body);
$img = $dom->find('img')[0];
if(is_null($img))
return redirect()->back()->withErrors('Add atleast one image in the post.');
该问题的解决方案是什么?
What would be the solution of the problem?
推荐答案
使用-> withInput()
返回数据
return redirect()->back()->withInput()->withErrors('Add atleast one image in the post.');
签入文档: https://laravel.com/中的旧输入
docs/master/requests
Check in docs : Old inputs
in https://laravel.com/docs/master/requests
这篇关于Laravel old()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文