v0.1.10
This commit is contained in:
26
kernel/modules/notification/channels/DatabaseChannel.php
Normal file
26
kernel/modules/notification/channels/DatabaseChannel.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\modules\notification\channels;
|
||||
|
||||
use kernel\Flash;
|
||||
use kernel\modules\notification\contracts\NotificationChannelInterface;
|
||||
use kernel\modules\notification\contracts\NotificationMessage;
|
||||
use kernel\modules\notification\models\User;
|
||||
|
||||
class DatabaseChannel implements NotificationChannelInterface
|
||||
{
|
||||
public function send(NotificationMessage $notification, User $user): bool
|
||||
{
|
||||
try {
|
||||
$user->notifications()->create([
|
||||
'message' => $notification->getMessage(),
|
||||
'data' => $notification->toArray()
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Flash::setMessage("error", $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user