Validation Laravel-如何处理PUT表单上的错误?

Validation Laravel-如何处理PUT表单上的错误?,validation,laravel,laravel-5,Validation,Laravel,Laravel 5,我正在使用Laravel5.2,希望以编辑形式验证一些数据。我的目标应该是显示错误,并在输入字段中保留错误的数据 我的问题是输入由ContentRequest验证,而FormRequest返回 $this->redirector->to($this->getRedirectUrl()) ->withInput($this->except($this->dontFlash))

我正在使用Laravel5.2,希望以编辑形式验证一些数据。我的目标应该是显示错误,并在输入字段中保留错误的数据

我的问题是输入由
ContentRequest
验证,而
FormRequest
返回

$this->redirector->to($this->getRedirectUrl())
                                ->withInput($this->except($this->dontFlash))
                                ->withErrors($errors, $this->errorBag);
到目前为止还不错。下一步调用控制器中的
edit
操作,并覆盖所有参数

我目前所做的:

ContentController

public function edit($id)
{
    $content = Content::find($id);

    return view('contents.edit', ['content' => $content]);
}

public function update(ContentRequest $request, $id)
{
    $content = Content::find($id);

    foreach (array_keys(array_except($this->fields, ['content'])) as $field) {
        $content->$field = $request->get($field);
    }
    $content->save();

    return redirect(URL::route('manage.contents.edit', array('content' => $content->id)))
        ->withSuccess("Changes saved.");
}
class ContentRequest extends Request
{
    public function authorize()
    {
        return true;
    }
    public function rules()
    {
        return [
            'title' => 'required|min:3',
            'body' => 'required|min:3'
        ];
    }
}
内容请求

public function edit($id)
{
    $content = Content::find($id);

    return view('contents.edit', ['content' => $content]);
}

public function update(ContentRequest $request, $id)
{
    $content = Content::find($id);

    foreach (array_keys(array_except($this->fields, ['content'])) as $field) {
        $content->$field = $request->get($field);
    }
    $content->save();

    return redirect(URL::route('manage.contents.edit', array('content' => $content->id)))
        ->withSuccess("Changes saved.");
}
class ContentRequest extends Request
{
    public function authorize()
    {
        return true;
    }
    public function rules()
    {
        return [
            'title' => 'required|min:3',
            'body' => 'required|min:3'
        ];
    }
}
我怎样才能解决这个问题?表单如下所示:

<form action="{!! URL::route('manage.contents.update', array('content' => $content->slug)) !!}"
          id="site-form" class="form-horizontal" method="POST">
        {!! method_field('PUT') !!}
        {!! csrf_field() !!}

        <div class="form-group {{ $errors->has('title') ? 'has-error' : '' }}">
            <label for="title" class="col-sm-2 control-label">Title</label>

            <div class="col-sm-10">
                <input type="text" class="form-control" name="title" id="title" placeholder="Title"
                       value="{{ $content->title }}">

                @if ($errors->has('title'))
                    <span class="help-block">
                        <strong>{{ $errors->first('title') }}</strong>
                    </span>
                @endif
            </div>
        </div>
    </form>

{!!方法_字段('PUT')!!}
{!!csrf_field()!!}
标题
@如果($errors->has('title'))
{{$errors->first('title')}
@恩迪夫

尝试以下方法:



请注意
属性。还可以查找并检索旧数据

尝试以下操作:



请注意
属性。另外,查找
检索旧数据

您是如何构造表单的?您是如何构造表单的?谢谢,解决方案谢谢,解决方案