8000 [11.x] Allow `readAt` method to use in database channel (#54729) · laravel/framework@120f07f · GitHub
[go: up one dir, main page]

Skip to content

Commit 120f07f

Browse files
[11.x] Allow readAt method to use in database channel (#54729)
* Allow default readed notification * Update DatabaseChannel.php * Update NotificationDatabaseChannelTest.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 5082a0c commit 120f07f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Illuminate/Notifications/Channels/DatabaseChannel.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ protected function buildPayload($notifiable, Notification $notification)
3636
? $notification->databaseType($notifiable)
3737
: get_class($notification),
3838
'data' => $this->getData($notifiable, $notification),
39-
'read_at' => null,
39+
'read_at' => method_exists($notification, 'initialDatabaseReadAtValue')
40+
? $notification->initialDatabaseReadAtValue($notifiable)
41+
: null,
4042
];
4143
}
4244

tests/Notifications/NotificationDatabaseChannelTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Tests\Notifications;
44

5+
use Carbon\Carbon;
56
use Illuminate\Notifications\Channels\DatabaseChannel;
67
use Illuminate\Notifications\Messages\DatabaseMessage;
78
use Illuminate\Notifications\Notification;
@@ -60,7 +61,7 @@ public function testCustomizeTypeIsSentToDatabase()
6061
'id' => 1,
6162
'type' => 'MONTHLY',
6263
'data' => ['invoice_id' => 1],
63-
'read_at' => null,
64+
'read_at' => Carbon::now()->toDateTimeString(),
6465
'something' => 'else',
6566
]);
6667

@@ -88,6 +89,11 @@ public function databaseType()
8889
{
8990
return 'MONTHLY';
9091
}
92+
93+
public function initialDatabaseReadAtValue()
94+
{
95+
return Carbon::now();
96+
}
9197
}
9298

9399
class ExtendedDatabaseChannel extends DatabaseChannel

0 commit comments

Comments
 (0)
0