5
votes

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();
    }
}
?>
1
add use ValidatesRequests; traitLeo
Still getting the same error for some reason.Sean O
are u following laravel 5.3 lectures while having another version installed ? Prolly u dont wanna throw an exception to the user, instead u wanna display the exceptios so do following: if($validator->fails() return redirect('post/create') ->withErrors($validator) ->withInput(); )Leo
that is not a tutorial for Laravel 5.5 ... as that method no longer exists. You can't follow a tutorial that is using a different version of Laravel than you do unless you know all the differences between the versions, or you will run into problems like this.lagbox
im not really sure why you are overriding this method at all, as there is no need to ... after registration a Registered event is fired that you can listen to ... that is where any code needed to run after a successful registration should golagbox

1 Answers

11
votes

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);
        }