Ошибка проверки при обновлении

Я использую laravel 4.2, и у меня есть следующая проблема:

Моя проверка правильно работает в функции Store, но когда я использую тот же код для проверки данных в функции обновления, валидатор работает, но неправильно перенаправляет или показывает ошибки проверки. быть более конкретным; в функции обновления валидатор проверяет данные, но когда валидатор дает сбой, вместо перенаправления на страницу редактирования с ошибками проверки; перенаправляет на индексную страницу без сохранения новых данных. Вот мой код:

Модель

public static $rules= array(

    'location'=> 'required',
    'price'=> 'required|numeric',
    'info'=> 'required'
);

Контроллер (код для магазина)

public function store()
 {

    $v=Validator::make(Input::all(), Estate:: $rules);

    if ($v->fails())
    {
        return Redirect ::route ('estates.create')
        ->withInput(Input::all())
        ->withErrors($v);
    }
    else
        {

    $userid = Auth::user()->getId();

    $estate = new Estate;
    $estate-> location = Input :: get('location');
    $estate-> price = Input::get('price');
    $estate-> info = Input::get ('info');

    $estate->user_id = $userid;

    $estate->save();

    return Redirect::to('estates');
        }
}

Просмотр для создания

 {{Form::Open(array ('url'=>'estates')) }}


    <div class="form-group {{$errors->has('location') ? 'has-error' : ''}}">
      <label for="location">Location:</label>
      <input type="string" name="location" value="{{{ Input::old('location') }}}" class="form-control">
      {{$errors->first('location','<span class="help-block">:message</span>')}}
  </div>

  <div class="form-group {{$errors->has('price') ? 'has-error' : ''}}">
    <label for="price">Price:</label>
    <input type="string" name="price" value="{{{ Input::old('price') }}}" class="form-control">
    {{$errors->first('price','<span class="help-block">:message</span>')}}
  </div>

  <div class="form-group {{$errors->has('info') ? 'has-error' : ''}}">
    <label for="info">Info:</label>
    <textarea input type ="text" class="col-md-12 input-block-level" rows="8" name="info" id="info"  class="from-control">{{{ Request::old('info') }}}</textarea>
    {{$errors->first('info','<span class="help-block">:message</span>')}}
  </div>

</div>

  <div class="container">

    <button type="Submit" class="btn btn-default">Add estate</button>

  </div>

{{Form::close()}}

Контроллер (код для обновления)

public function update($id)
{
    $v=Validator::make(Input::all(), Estate:: $rules);

    if ($v->fails())
    {
        return Redirect ::route ('estates.edit')
        ->withInput(Input::All())
        ->withErrors($v);
    }

    else
     {
        $userid = Auth::user()->getId();

        $estate = Estate::find($id);
        $estate-> location = Input::get('location');
        $estate-> price = Input::get('price');
        $estate-> info = Input::get ('info');

        $estate->user_id = $userid;

        $estate->save();

        return Redirect::to('estates');
     }
}

Посмотреть для обновления

 <div class="container">
{{Form::Open(array ('method'=>'patch' , 'route'=> array ('estates.update', $estate->id)))}}

  <div class="form-group {{$errors->has('location') ? 'has-error' : ''}}">
      <label for="">Location:</label>
      <input type="string" name="location" value="{{$estate->location}}" class="form-control">
      {{$errors->first('location','<span class="help-block">:message</span>')}}
  </div>


  <div class="form-group {{$errors->has('price') ? 'has-error' : ''}}">
    <label for="">Price:</label>
    <input type="string" name="price" value="{{$estate->price}}" class="form-control">
    {{$errors->first('price','<span class="help-block">:message</span>')}}
  </div>

  <div class="form-group {{$errors->has('info') ? 'has-error' : ''}}">
    <label for="">Info:</label>
    <textarea class="col-md-12 " rows="4" input type="text" name="info" id="info" class="form-control" > {{$estate->info}}</textarea>
  </div>
</div>
<div class="container">

  <button type="Submit" class="btn btn-default">Update</button>

  {{Form::close()}}
</div>

person Karakuri    schedule 11.12.2014    source источник


Ответы (1)


Я думаю, вы заменили это

return Redirect ::route ('estates.edit')

с этим

return Redirect ::route ('estates.edit', ['id' => $id])
person NULL    schedule 11.12.2014
comment
Тогда, пожалуйста, отметьте мой ответ как принятый ответ. - person NULL; 12.12.2014