mahdihty
4 years ago
7 changed files with 87 additions and 35 deletions
-
8app/Channels/Messages/SocketMessage.php
-
34app/Channels/SocketChannel.php
-
2app/Notifications/FcmNotification.php
-
52app/Notifications/SocketNotification.php
-
4app/Providers/AppServiceProvider.php
-
18config/socket.php
-
4routes/api.php
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Notifications; |
||||
|
|
||||
|
use App\Channels\Messages\SocketMessage; |
||||
|
use Illuminate\Bus\Queueable; |
||||
|
use Illuminate\Contracts\Queue\ShouldQueue; |
||||
|
use Illuminate\Notifications\Messages\MailMessage; |
||||
|
use Illuminate\Notifications\Notification; |
||||
|
|
||||
|
class SocketNotification extends Notification |
||||
|
{ |
||||
|
use Queueable; |
||||
|
|
||||
|
public $message; |
||||
|
|
||||
|
/** |
||||
|
* Create a new notification instance. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function __construct($message) |
||||
|
{ |
||||
|
$this->message = $message; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the notification's delivery channels. |
||||
|
* |
||||
|
* @param mixed $notifiable |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function via($notifiable) |
||||
|
{ |
||||
|
return ['socket']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the socket representation of the notification. |
||||
|
* |
||||
|
* @param mixed $notifiable |
||||
|
* @return SocketMessage |
||||
|
*/ |
||||
|
public function toSocket($notifiable) |
||||
|
{ |
||||
|
return (new SocketMessage()) |
||||
|
->data([ |
||||
|
'title' => $this->message['title'], |
||||
|
'body' => $this->message['body'], |
||||
|
]); |
||||
|
} |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
|
||||
|
/* |
||||
|
|-------------------------------------------------------------------------- |
||||
|
| FCM API Key |
||||
|
|-------------------------------------------------------------------------- |
||||
|
| |
||||
|
| This key allows you to send Push Notifications. To obtain this key go |
||||
|
| to the porject settings and click on the "Cloud Messaging" tab, now |
||||
|
| copy the API Key of "Legacy server key". |
||||
|
| |
||||
|
*/ |
||||
|
|
||||
|
'url' => env('SOCKET_URL'), |
||||
|
|
||||
|
]; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue