Skip to content
Advertisement

Call to a member function notify() on null in Laravel 8

I want to send an SMS to a mobile phone (if he had already turned on the two-factor authentication system).

So at LoginController I added this method:

JavaScript

And this loggendin method is inside of a trait called TwoFactorAuthentication, which goes like this:

JavaScript

Now the problem is when I want to log in, this message appears on the screen which is saying:

Error Call to a member function notify() on null

Which is referring to this line:

JavaScript

And this ActiveCodeNotification holds some settings for sending the SMS.

If you would like to visit that, here it is:

JavaScript

So what’s going wrong here that I get Call to a member function notify() on null while it’s two parameters have value.

So if you know, please let me know. I would really appreciate any idea from you guys…

Thanks.

Advertisement

Answer

Try this:

First, make sure your User model has the Notifiable trait.

Top of the User Model class:

JavaScript

After that:

JavaScript

And then…

Instead of

JavaScript

Use this

JavaScript

Or

Before calling auth()->logout();

use it at first:

JavaScript

then, you can call auth()->logout();

Worked for me recently

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement