Search code examples
phplaravelsentinel

Method [sendEmail] does not exist


I am new to laravel 5.3 . I am using cartalyst sentinel for authentication

Web.php

Route::post('/register','RegistrationController@register');
Route::get('/activate/{email}/{activationCode}' , 'RegistrationController@activate');

RegistrationController.php

public function register(Request $request){
    $user = Sentinel::register($request->all());
    $activation = Activation::create($user);
    $role = Sentinel::findRoleBySlug('student');
    $role->users()->attach($user);
    $this->sendEmail($user,$activation->code);
    Alert::info('Mail has been sent to activate your account', 'Confirmation Email')->persistent("Close this");
    return redirect::back();
}

authenticate method in registration controller -

public function activate($email,$activationCode){

    $user = User::whereEmail($email)->first();

    $sentinelUser = Sentinel::findById($user->id);

    if(Activation::complete($sentinelUser, $activationCode)){

        return redirect('/');

    }
}

this is the image of complete code of registrationController

when i tried to submit the button then i got this error -

BadMethodCallException in Controller.php line 82: Method [sendEmail] does not exist.

Please help me , Thanks


Solution


  • $this->sendEmail($user,$activation->code); is trying to call on a method that is supposed to be existing somewhere, but it's not finding it.

    You can simply define the function somewhere with all the logics you want. e.g.

    private function SendEmail($user, $activation->code) { // your logic goes here }

    Hope this will solve your problem....