marcioelias/laravel-notifications
Composer 安装命令:
composer require marcioelias/laravel-notifications
包简介
This package handle notifictation like push notifications, sms, etc. The focus is using AWS Services.
README 文档
README
The goal of this package is turn very easy the process of sending notifications using AWS SNS. It provides a facade to send notifications, and an API to be used to interact with the notifications (push notifications only).
Here are the endpoints available:
# used to create a endpoint ARN on AWS SNS Application # stores the ARN at users table on column device_token) POST /api/device-token
# used to get all notifications paginated # see config to customize per page number and FormResource class GET /api/notifications
# mark a notification as readed PUT /api/notification/{notification}/read
# mark a notification as unreaded PUT /api/notification/{notification}/unread
Installation
You can install the package via composer:
composer require marcioelias/laravel-notifications
Publishing Resources
To see all available publishable resources, run:
php artisan vendor:publish --provider="MarcioElias\LaravelNotifications\LaravelNotificationsServiceProvider"
Or publish specific resources using tags:
Publish the migrations:
php artisan vendor:publish --tag="laravel-notifications-migrations"
Publish the config file (Optional, just required if you need to config some customizations):
php artisan vendor:publish --tag="laravel-notifications-config"
Publish translations:
php artisan vendor:publish --tag="laravel-notifications-translations"
Publish routes:
php artisan vendor:publish --tag="laravel-notifications-routes"
Publish custom fields migration:
php artisan vendor:publish --tag="laravel-notifications-custom-fields-migration"
This is the contents of the published config file:
return [ /* |-------------------------------------------------------------------------- | Supported Push Notification Providers |-------------------------------------------------------------------------- | | Currently this package can send push notification with AWS SNS Service. | Please not that using AWS services, this package will be using by default | the default configurations for AWS on .env file. | | Here are the keys that can be used to configure the service provider: | - aws_sns | */ 'push_service_provider' => env('PUSH_SERVICE_PROVIDER', 'aws_sns'), /* |-------------------------------------------------------------------------- | AWS SNS Application ARN |-------------------------------------------------------------------------- | | The ARN of the application that will be used to send push notifications. | This ARN is used to create a platform endpoint. | */ 'aws_sns_application_arn' => env('AWS_SNS_APPLICATION_ARN', null), /* |-------------------------------------------------------------------------- | Tables with alertable trait on his models |-------------------------------------------------------------------------- | | Will be executed a migration to create device_token column on each table | listed here. | */ 'alertable_tables' => [ 'users', ], /* |-------------------------------------------------------------------------- | API Endpoints configuration |-------------------------------------------------------------------------- | | Allow the configuration of the API endpoints for the notifications | resources. | */ 'api' => [ 'notification_resource' => \MarcioElias\LaravelNotifications\Resources\NotificationResource::class, 'pagination' => 20, ] ];
After config the package, run the migrations
php artisan migrate
Usage
Sending a push notification
use MarcioElias\LaravelNotifications\LaravelNotifications; ... public function myFunction(): void { //my own code ... LaravelNotifications::sendPush( title: 'my title', body: 'Hello, this is a push notification' ) }
You can add some custom object to the push notification.
use MarcioElias\LaravelNotifications\LaravelNotifications; ... public function myFunction(): void { //my own code ... LaravelNotifications::sendPush( title: 'my title', body: 'Hello, this is a push notification', data: [ 'id' => Auth::id(), 'name' => Auth::user()->name ] ) }
Custom Fields in Notifications Table
You can add custom fields to the notifications table to store additional data with each notification.
Step 1: Publish the custom fields migration
php artisan vendor:publish --tag="laravel-notifications-custom-fields-migration"
The migration will be published to:
- Default:
database/migrations/ - Tenancy for Laravel: Automatically detected and published to
database/tenantorDatabase/Tenant - Custom path: Configure in
config/notifications.phpor viaNOTIFICATIONS_MIGRATIONS_PATHenv variable
Configuring custom migrations directory:
If you're using Tenancy for Laravel, the package will automatically detect it. You can also manually configure the path:
Option 1: Via config file (config/notifications.php):
'migrations_path' => 'database/tenant', // or 'Database/Tenant'
Option 2: Via environment variable (.env):
NOTIFICATIONS_MIGRATIONS_PATH=database/tenant
Step 2: Edit the migration file
Open the published migration file and add your custom fields:
public function up() { Schema::table('notifications', function (Blueprint $table) { $table->string('category')->nullable(); $table->integer('priority')->default(0); $table->foreignId('related_id')->nullable(); // Add your custom fields here }); }
Step 3: Run the migration
php artisan migrate
Step 4: Use custom fields when sending notifications
use MarcioElias\LaravelNotifications\LaravelNotifications; LaravelNotifications::sendPush( to: $user, title: 'New Order', body: 'You have a new order', data: ['order_id' => 123], customFields: [ 'category' => 'order', 'priority' => 5, 'related_id' => 123 ] );
The custom fields will be saved in the notifications table along with the standard notification data.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
marcioelias/laravel-notifications 适用场景与选型建议
marcioelias/laravel-notifications 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel-notifications」 「MarcioElias」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 marcioelias/laravel-notifications 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marcioelias/laravel-notifications 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 marcioelias/laravel-notifications 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Realtime notifications for Laravel Enso
Push notifications dependency for LaravelLiberu
Multiple flash messages with Laravel
A useful wrapper around Laravel Notifications that support its artisan command
Push notifications dependency for LaravelEnso
A Laravel package for integrating with Zoho Cliq, allowing you to send messages, notifications, and rich content seamlessly from your Laravel application.
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-27