Laravel:商店方法验证

时间:2015-01-22 10:17:18

标签: php laravel-4

我有ConferencesController store方法。在我看来,我发布到conferences.store并在Redirect::to方法中执行验证逻辑和store

public function store()
{
    $validator = Validator::make(Input::all(), Conference::$rules);

    if($validator->fails()){
        Redirect::back()->with('message', 'Er ging iets mis, zie de errors hieronder.')->withErrors($validator)->withInput();
    } else {
        $conference = new Conference();
        $conference->title = Input::get('title');
        $conference->description = Input::get('description');
        $conference->location = Input::get('location');
        $conference->plannedTime = Input::get('plannedTime');
        $conference->save();
    }
}

验证可能会失败,或者没有,但控制器不执行Redirect::to,这是一个已知问题吗?我该如何解决?

1 个答案:

答案 0 :(得分:0)

试试这个:

return Redirect::to('/')->with('message', 'Er ging iets mis, zie de errors hieronder')->withErrors($validator)->withInput();