Laravel: 在存储方法中验证

Laravel: validation in store method

我有一个 ConferencesControllerstore 方法。在我看来,我 POST 到 conferences.store 并在 store 方法中执行我的验证逻辑和 Redirect::to

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,这是一个已知问题吗?我该如何解决?

试试这个:

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