Laravel Routing返回空白页面

时间:2015-03-25 12:21:03

标签: php laravel routing

让它有点短。我刚刚制作了一个完整的控制器,路线和视图的注册表。现在我知道为它使用模型是常识,而在控制器中只调用模型中的方法。所以我认为可以解决这个问题。现在,当我注册一个帐户时,我得到一个空白页面。我打赌重定向是错误的,但我无法修复它也许你可以吗?

RegisterController.php

public function doRegister(){
    $user = new User();
    $user->doRegister();

}

User.php(模特)

public function doRegister()
{
    // process the form here

    // create the validation rules ------------------------
    $rules = array(
        'username'             => 'required|unique:users',
        'email'            => 'required|email|unique:users',
        'password'         => 'required|min:5',
        'serial_key'            => 'required|exists:serial_keys,serial_key|unique:users'
    );
    // create custom validation messages ------------------
    $messages = array(
        'required' => 'The :attribute is important.',
        'email'  => 'The :attribute is not a legit e-mail.',
        'unique' => 'The :attribute is already taken!'
    );

    // do the validation ----------------------------------
    // validate against the inputs from our form
    $validator = Validator::make(Input::all(), $rules);

    // check if the validator failed -----------------------
    if ($validator->fails()) {

        // get the error messages from the validator
        $messages = $validator->messages();

        // redirect our user back to the form with the errors from the validator
        return Redirect::to('/register')
            ->withErrors($validator)
            ->withInput(Input::except('password', 'password_confirm'));
    } else {
        // validation successful ---------------------------

        // our duck has passed all tests!
        // let him enter the database

        // create the data for our duck
        $duck = new User;
        $duck->username = Input::get('username');
        $duck->email = Input::get('email');
        $duck->password = Hash::make(Input::get('password'));
        $duck->serial_key = Input::get('serial_key');


        // save our user

        $duck->save();

        // redirect with username ----------------------------------------

        return Redirect::to('/registered')->withInput(Input::old('username'));

    }
}

2 个答案:

答案 0 :(得分:1)

你需要制作$ user-> doRegister();退货声明

你必须在RegisterController中

public function doRegister(){
$user = new User();
return $user->doRegister();
}

答案 1 :(得分:0)

试试这个

return Redirect::to('/registered')
            ->with('bill_no', Input::get('username'));

在'/ registered'控制器中,..  使用这个

$username = Session::get("username");

以上为我工作,......