Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alimohdrajwa's avatar

Getting notification ID immediately after sending notification in Laravel 8

I'm working on a Laravel 8 application where I need to retrieve the notification ID immediately after sending a notification. However, I'm facing difficulties in obtaining the notification ID using the standard Laravel notification system.

// Controller method public function roomCollabrationrequest(CollabrationRequestSend $request) { // ... (existing code)

$collabration = RoomCollabration::create([
    'user_id' => $request->user_id,
    'room_id' => $request->room_id,
    'status' => 'pending',
]);

$receiver = User::where('id', $request->user_id)->first();
$notificationSent = $receiver->notify(new CollabrationRequestNotification($collabration));

// Trying to get the notification ID
$notificationId = $notificationSent->id;

// ... (existing code)

}

// CollabrationRequestNotification.php

0 likes
0 replies

Please or to participate in this conversation.