gpt4 book ai didi

php - Laravel 旧()不工作

转载 作者:可可西里 更新时间:2023-11-01 13:39:50 26 4
gpt4 key购买 nike

{!! 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() !!}

这是我的表单,但是当我提交它并在服务器端验证它并重定向到同一页面时,它不显示旧值。

Controller 端

$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.');

问题的解决方案是什么?

最佳答案

使用->withInput()返回数据

    return redirect()->back()->withInput()->withErrors('Add atleast one image in the post.');

checkin 文档:旧输入 https://laravel.com/docs/master/requests

关于php - Laravel 旧()不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41659717/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com