b4zz4r/laravel-firebase-notifications

此包已被弃用且不再维护。未建议任何替代包。

用于集成 Firebase Messaging 作为 Laravel 通知的薄层

此包尚未发布版本,且可用的信息很少。


README

用于集成 Firebase Messaging 作为 Laravel 通知的薄层

要求

  • PHP >= 7.1
  • Laravel >= 5.5 或 6.x

安装

$ composer require "b4zz4r/laravel-firebase-notifications"

这就是全部,感谢包自动发现。

设置

只需将 Firebase 凭据 JSON 文件放置于 storage/firebase.credentials.json

高级设置

或者您可以使用 .env 文件更改文件位置。

FIREBASE_CREDENTIALS="/etc/firebase.credentials.json"

或者将 JSON 内容直接放置到环境变量中。这对于云服务来说很酷。

FIREBASE_CREDENTIALS="{\"type\": \"service_account\", ...}"

基本用法

将新方法 routeNotificationForFirebase 添加到您的可通知实体中,它返回设备 ID。

    /**
     * It could be one device
     */
    public function routeNotificationForFirebase()
    {
        return $this->device_id;
    }
    
    /**
     * Or you can return array for multicast
     */
    public function routeNotificationForFirebase()
    {
        return $this->devices()->get()->pluck('id');
    }

在通知实体中,您应该在 via() 方法中添加 firebase

    public function via(): array
    {
        return ['firebase', /* 'email', 'database', 'etc...'*/];
    }

然后您可以在 toFirebase() 方法中构造 CloudMessage

    public function toFirebase(): Messaging\CloudMessage
        $notification = Messaging\Notification::create('I <3 laravel', 'It is true');
        return Messaging\CloudMessage::new()->withNotification($notificatin);
    }

请参阅官方 PHP SDK 文档以了解所有可能的完整用法。