laravel编辑表单验证重定向到错误的路由

时间:2014-04-18 16:58:43

标签: forms laravel-4 edit

您好我有管理,我从数据库编辑记录

    public function edit($id)
{
    $producer =  Producer::find($id);
    if (is_null($producer)) return Redirect::to('admin');

    return View::make('edit')->with('producer', $producer);
}

public function update()
{
    $validation = Producer::validate(Input::all());
    $id = Input::get('id');
    if ($validation->fails()) {
        return Redirect::to('/admin/edit/{$id}')->withErrors($validation);
    } else {

        Producer::find($id)->update(array(
            'title' => Input::get('title'),
            'body' => Input::get('body'),
            'url' => Input::get('url')
        ));

        return Redirect::to('/admin')->with('flash_message','Záznam editovaán');
    }


}

查看编辑表单

    @extends('layouts.layout')

@section('content')

<div class="container">
    <div class="col-md-8">
        <div class="row">
            <div class="col-md-8">
                @if($errors->has())
                    <ul>
                        {{ $errors->first('title', '<li>:message</li>') }}
                        {{ $errors->first('body', '<li>:message</li>') }}
                        {{ $errors->first('url', '<li>:message</li>') }}
                    </ul>
                @endif
                {{ Form::open(array('url' => '/admin/update')) }}
                <p>{{ Form::label('title', 'Název služby') }}</p>
                <p>{{ Form::text('title', $producer->title) }}</p>
                <p>{{ Form::label('body', 'Popis') }}</p>
                <p>{{ Form::textarea('body',$producer->body) }}</p>
                <p>{{ Form::label('url', 'Adresa webu') }}</p>
                <p>{{ Form::text('url', $producer->url) }}</p>
                <p>{{ Form::hidden('id', $producer->id) }}</p>
                <p>{{ Form::submit('Uložit',array('class' => 'btn btn-default')) }}</p>
                {{ Form::close() }}
                <hr>
            </div>
        </div>
    </div>
</div>
@stop

编辑记录是功能,但当验证faild重定向到编辑表单isnt功能

路线档案

    Route::get('/', 'HomeController@showWelcome');

Route::get('/detail/{id}', 'HomeController@detail');

Route::get('/add', 'HomeController@add');

Route::post('/create', 'HomeController@create');

Route::get('login', 'SessionController@create');

Route::get('logout', 'SessionController@destroy');

Route::resource('sessions', 'SessionController');

Route::get('admin', 'AdminController@index')->before('auth');

Route::get('/admin/delete/{id}', 'AdminController@delete');

Route::get('/admin/edit/{id}', 'AdminController@edit');

Route::get('/admin/state/{id}', 'AdminController@state');

Route::get('/o_nas', 'AboutController@index');

Route::filter('pattern: admin/*', 'auth');

Route::post('/admin/update/', 'AdminController@update');

请帮我编辑表格

我的验证规则

class Producer extends Eloquent {

protected $fillable = array('title','body','url');

public static $rules = array(
    'title'=>'required|min:5',
    'body'=>'required|min:10',
    'url' => 'required|url'
);

public static function validate($data) {
    return Validator::make($data, static::$rules);
}

}

1 个答案:

答案 0 :(得分:0)

在更新功能中我从

更改重定向
return Redirect::to('/admin/edit/{$id}')->withErrors($validation);

return Redirect::back()->withErrors($validation);

现在没事了

我原以为两个重定向都是重定向到同一页面