-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Notifications; | ||
|
||
use Illuminate\Notifications\Notification; | ||
|
||
class RootChannel | ||
{ | ||
/** | ||
* Send the given notification. | ||
*/ | ||
public function send(object $notifiable, Notification $notification): void | ||
{ | ||
$data = $notification->toRoot($notifiable)->toArray(); | ||
|
||
$notifiable->rootNotifications()->create($data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Notifications; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
|
||
class RootMessage implements Arrayable | ||
{ | ||
/** | ||
* The message subject. | ||
*/ | ||
protected ?string $subject = null; | ||
|
||
/** | ||
* The message content. | ||
*/ | ||
protected ?string $message = null; | ||
|
||
/** | ||
* Create a new message instance. | ||
*/ | ||
public function __construct(?string $subject = null, ?string $message = null) | ||
{ | ||
$this->subject = $subject; | ||
$this->message = $message; | ||
} | ||
|
||
/** | ||
* Set the message subject. | ||
*/ | ||
public function subject(string $value): static | ||
{ | ||
$this->subject = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set the message message. | ||
*/ | ||
public function message(string $value): static | ||
{ | ||
$this->message = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the array form of the message. | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'subject' => $this->subject, | ||
'message' => $this->message, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Notifications; | ||
|
||
use Cone\Root\Notifications\RootChannel; | ||
use Cone\Root\Notifications\RootMessage; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Notifications\Notification; | ||
|
||
abstract class RootNotification extends Notification implements ShouldQueue | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* Get the notification's delivery channels. | ||
* | ||
* @return array<int, string> | ||
*/ | ||
public function via(object $notifiable): array | ||
{ | ||
return [RootChannel::class]; | ||
} | ||
|
||
/** | ||
* Get the Root Message representation of the notification. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
abstract public function toRoot(object $notifiable): RootMessage; | ||
} |