Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

throwValidationException method does not exist

Tags:

laravel

I'm following a tutorial for laravel 5.5 on over overriding the REGISTER method in RegisterController, but i am getting error saying "Method [throwValidationException] does not exist on [App\Http\Controllers\Auth\RegisterController]", not sure why?

<?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();
    }
}
?>
like image 560
Sean O Avatar asked Dec 02 '17 23:12

Sean O


1 Answers

as laravel 5.5 main contrller for register, you can use only this line:

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

insted of these lines

$validator = $this->validator($request->all());
        if ($validator->fails()) {
            $this->throwValidationException($request, $validator);
        }
like image 70
Mohammed Fahjan Avatar answered Nov 15 '22 12:11

Mohammed Fahjan