2017-01-15 2 views
0
{!! 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() !!} 

이것은 내 양식이지만 제출하고 서버 쪽에서 유효성을 검사하여 동일한 페이지로 리디렉션하면 이전 값이 표시되지 않습니다.Laravel old() not working

어떤 문제의 해결책이 될 것입니다

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

컨트롤러 측? 다시 데이터

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

확인에 갈

답변

3

사용 ->withInput() : Old inputs이 일 덕분에

+0

https://laravel.com/docs/master/requests에서, 그것은 어떤 문서가? 그 링크도 게시 할 수 있습니까? –

+0

예 응답에서 https://laravel.com/docs/master/requests – C2486

+0

의 오래된 입력이 업데이트되면 다른 사람들에게 도움이됩니다. –