2015-03-25 126 views
1

以使其略短。我只是做了一个注册表格,与控制器,路线和视图充分合作。现在我知道使用模型是常识,并且在控制器中只调用模型中的方法。所以我想好了让我们解决这个问题。现在,当我注册一个帐户,我得到一个空白页。我敢打赌,重定向错了,但我无法修复它,也许你可以?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')); 

    } 
} 

回答

1

你需要$用户> doRegister();在RegisterController return语句

你要做的

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

哦哇..非常感谢兄弟! – 2015-03-25 12:26:56

0

试试这个

return Redirect::to('/registered') 
      ->with('bill_no', Input::get('username')); 
在 '/注册' 控制器

,.. 使用这种

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

上面为我工作,...

+0

谢谢先生回复。已经有了答案! – 2015-03-25 12:41:48

+0

为你而高兴,.. – m2j 2015-03-25 12:52:23