You will never get to the commit statement with your DD there
Why are you even using a transaction - pointless in this context
Hi everybody ! I've read the Notifications documentation, but the Mark as Read part is so brief and manages unread Notifications as a whole and not individually. So, I'm using Eloquent to get the notification by id, is ok, right? Thing is, as you can see in the code, I've tried multiple ways, but unsuccessfully. The read_at value changes in the method but is not persisted in DB.
public function handler($notification_id) {
try {
DB::beginTransaction();
/* MARK as read not working even though next variable gets the correct notification (its datatype is DatabaseNotification)*/
$notification = auth()->user()
->unreadNotifications
->where('id', $notification_id)->first();
$notification->markAsRead(); // 1st way
auth()->user()->Notifications
->where('id', '=', $notification_id)
->markAsRead(); // 2nd way
$notification->update(
['read_at'=>Carbon::now(), // 3rd way
]);
$notification->save(); // even try this
dd($notification); // shows read_at with correct datetime
DB::commit();
// and catch staff
What should I do ?
Thanks in advance!
@martin.fdm and if you remove the transaction?
Please or to participate in this conversation.