From d19e25fac7682387f766fa65ec4328e2e7498e62 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Wed, 23 Jul 2025 22:40:20 +0300 Subject: [PATCH 1/2] Add readNotifications relationship method --- notifications.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/notifications.md b/notifications.md index 0e30611e15..917a9c1d73 100644 --- a/notifications.md +++ b/notifications.md @@ -981,6 +981,16 @@ foreach ($user->notifications as $notification) { } ``` +If you want to retrieve only the "read" notifications, you may use the `readNotifications` relationship. Again, these notifications will be sorted by the `created_at` timestamp with the most recent notifications at the beginning of the collection: + +```php +$user = App\Models\User::find(1); + +foreach ($user->readNotifications as $notification) { + echo $notification->type; +} +``` + If you want to retrieve only the "unread" notifications, you may use the `unreadNotifications` relationship. Again, these notifications will be sorted by the `created_at` timestamp with the most recent notifications at the beginning of the collection: ```php From c1b71149a641627d23154d682d0487320f4bd387 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 23 Jul 2025 17:37:12 -0500 Subject: [PATCH 2/2] Update notifications.md --- notifications.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/notifications.md b/notifications.md index 917a9c1d73..fdb8ff6c5f 100644 --- a/notifications.md +++ b/notifications.md @@ -981,22 +981,22 @@ foreach ($user->notifications as $notification) { } ``` -If you want to retrieve only the "read" notifications, you may use the `readNotifications` relationship. Again, these notifications will be sorted by the `created_at` timestamp with the most recent notifications at the beginning of the collection: +If you want to retrieve only the "unread" notifications, you may use the `unreadNotifications` relationship. Again, these notifications will be sorted by the `created_at` timestamp with the most recent notifications at the beginning of the collection: ```php $user = App\Models\User::find(1); -foreach ($user->readNotifications as $notification) { +foreach ($user->unreadNotifications as $notification) { echo $notification->type; } ``` -If you want to retrieve only the "unread" notifications, you may use the `unreadNotifications` relationship. Again, these notifications will be sorted by the `created_at` timestamp with the most recent notifications at the beginning of the collection: +If you want to retrieve only the "read" notifications, you may use the `readNotifications` relationship: ```php $user = App\Models\User::find(1); -foreach ($user->unreadNotifications as $notification) { +foreach ($user->readNotifications as $notification) { echo $notification->type; } ```