2015-03-25 118 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