Obvious question, are you logged in?
Call to a member function notify() on null
I get this error message. this is my code
$id= $bank['data']['metadata']['buyer_user_id'];
$users = user::find($id);
auth()->user()->notify(new MergedMechanic($users));
i just want to trigger a notification but when d page loads i get this error message
yes I am
Are you sure? add a dd(auth()->user()); just before your auth()->user()->notify() and see what it says.
What version Laravel are you on?
Do you see use Notifiable; at the top of the User model?
when I did dd(auth()->user()); it returned null. what should I do to fix this
@Snapey I did see it there
it returned null. what should I do to fix this
That's hard to say based solely on the 3 lines of code you're showing. This method should only be able to be used by people who are authenticated and logged in. There are several ways to do that, but I don't know anything about your app, how it's structured, the routes, etc.
Easiest thing to do is create a route group that uses the auth middleware, and define all of the routes that require a logged in user within it.
// any routes defined within this route group would require a user to be logged in first, or it will throw an error
Route::middleware(['auth'])->group(function () {
Route::get('/', function () {
});
Route::get('user/profile', function () {
});
});
But as I said, I know nothing about your app or if this would be good to do for your use case.
another option is to just check if they are logged in
if (Auth::check()) {
$id= $bank['data']['metadata']['buyer_user_id'];
$users = user::find($id);
auth()->user()->notify(new MergedMechanic($users));
}
There are lots of ways.
@CRONIX - @cronix I have the same error...
here is my route:
Route::post('iaccs-hook', 'WebhookController@handle');
and my controller:
public function handle(Request $request){
if (Auth::check()) {
$data = $request;
// $user = auth()->user()->hasRole('superadmin');
\Log::info($data);
auth()->user()->notify(new WebhookNotification($data));
}
}
error:
Call to a member function notifyNow() on null {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function notifyNow() on null at C:\\wamp64\\www\\iaccs-admin-console\\app\\Http\\Controllers\\WebhookController.php:31)
Where is this request to the webhook coming from? You'll only get the authed user instance if the request is originating from the authenticated users browser to your app.
Please or to participate in this conversation.