Laravel 4不显示old :: input()

时间:2014-04-03 07:08:07

标签: session laravel-4

laravel4的新手并且无法获得基本的工作,例如:

function doRegister() {

    try {

        $email = Input::get('email');
        $type = Input::get('type'); // <-- Data from radio button

        # Check if email exists
        if ( User::where('email','=',$email)->count() > 0 ) {
            # This account already exists
            throw new Exception( 'This email already in use by someone else.' );
        }

    } catch (Exception $e) {
        return Redirect::to('/')->withInput()->with('message', $e->getMessage() );
    }


}

现在在homepage控制器上(/)我无法读取Input::old('type');的值 它返回空。怎么样?

1 个答案:

答案 0 :(得分:1)

请改为尝试:

function doRegister()
{
    $rules = array('email' => 'required|email|unique:users');
    $validator = Validator::make(Input::all(), $rules);
    if ($validator->fails()) {
        return Redirect::to('/')->withInput()>withErrors($validator);
    }
    else {
        $email = Input::get('email');
        $type = Input::get('type');
        // Register...
    }
}

您可以使用以下方法检索验证错误:

$errors->first('email');