2017-12-02 112 views
0

我正在按照覆盖RegisterController中的REGISTER方法的laravel 5.5的教程,但我收到错误说“方法[throwValidationException]不存在于[App \ Http \ Controllers \ Auth \ RegisterController]“,不知道为什么?throwValidationException方法不存在

<?php 
/** 
* Over-ridden the register method from the "RegistersUsers" trait 
* Remember to take care while upgrading laravel 
*/ 
public function register(Request $request) 
{ 
    // Laravel validation 
    $validator = $this->validator($request->all()); 
    if ($validator->fails()) 
    { 
     $this->throwValidationException($request, $validator); 
    } 
    // Using database transactions is useful here because stuff happening is actually a transaction 
    // I don't know what I said in the last line! Weird! 
    DB::beginTransaction(); 
    try 
    { 
     $user = $this->create($request->all()); 
     // After creating the user send an email with the random token generated in the create method above 
     $email = new EmailVerification(new User(['email_token' => $user->email_token, 'name' => $user->name])); 
     Mail::to($user->email)->send($email); 
     DB::commit(); 
     return back(); 
    } 
    catch(Exception $e) 
    { 
     DB::rollback(); 
     return back(); 
    } 
} 
?> 
+0

添加使用ValidatesRequests的;性状 –

+0

由于某些原因仍然出现相同的错误。 –

+1

是否在安装另一个版本后遵循laravel 5.3讲座?如果($ validator-> failed()返回重定向('post/create') - > withErrors($ validator) - > withInput();) –

回答

0

为laravel 5.5寄存器主要contrller,你只能使用这条线:

$this->validator($request->all())->validate(); 

insted的这些线路

$validator = $this->validator($request->all()); 
     if ($validator->fails()) { 
      $this->throwValidationException($request, $validator); 
     }