%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/diaspora/api/app/Notifications/
Upload File :
Create Path :
Current File : /var/www/html/diaspora/api/app/Notifications/NotifyUsersForNewPostCreatedNotification.php

<?php

namespace App\Notifications;

use App\Models\Device;
use App\Models\Post;
use Benwilkins\FCM\FcmMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;

class NotifyUsersForNewPostCreatedNotification extends Notification implements ShouldQueue
{
    use Queueable;
    /**
     * @var Post
     */
    private $post;
    /**
     * @var int
     */
    private $badge;

    /**
     * Create a new notification instance.
     *
     * @param Post $post
     * @param int $badge
     */
    public function __construct(Post $post, $badge = 1)
    {
        $this->post = $post;
        $this->badge = $badge;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @return array
     */
    public function via()
    {
        return ['fcm'];
    }

    /**
     * @param Device $device
     * @return FcmMessage
     */
    public function toFcm(Device $device)
    {
        $message = new FcmMessage();
        $message->content([
            'badge' => $this->badge,
            'title' => $this->post->getTranslation($device->language, true)->title,
            'body'  => $this->post->getTranslation($device->language, true)->short_desc,
        ]);
        $message->data([
            'post_id' => $this->post->id,
        ]);
        $message->priority(FcmMessage::PRIORITY_HIGH);

        return $message;
    }
}

Zerion Mini Shell 1.0