williamcruzme/laravel-notification-settings
Composer 安装命令:
composer require williamcruzme/laravel-notification-settings
包简介
A Laravel package that allows you to check the notification settings before send them.
README 文档
README
laravel-notification-settings is a Laravel package that allows you to check the notification settings before send them.
💿 Installation
composer require williamcruzme/laravel-notification-settings
🏁 Getting Started
1. Adding trait
In your user model add the Notifiable trait. This trait supports custom guards:
<?php namespace App; use Illuminate\Foundation\Auth\User as Authenticatable; use Millions\Notifications\Notifiable; class User extends Authenticatable { use Notifiable; }
2. Running migrations
php artisan migrate
Sometimes you may need to customize the migrations. Using the vendor:publish command you can export the migrations:
php artisan vendor:publish --tag=migrations
3. Creating seeder
Add all notifications that require settings. Notification that are not added will be sent without verification:
php artisan make:seeder NotificationTypesTableSeeder
/** * Run the database seeds. * * @return void */ public function run() { DB::table('notification_types')->insert([ 'name' => 'App\\Notifications\\Welcome', 'display_text' => 'Welcome message', 'status' => true, ]); }
4. Adding routes
Using the Notification facade to import the routes for manage the settings:
Notification::routes();
🚀 Usage
Using The Notifiable Trait
This trait contains one method that may be used to send notifications: notify. The notify method check if the user wants to receive it, and expects to receive a notification instance:
use App\Notifications\InvoicePaid; $user->notify(new InvoicePaid($invoice));
Using The Notification Facade
Alternatively, you may send notifications via the Notification facade. This is useful primarily when you need to send a notification to multiple notifiable entities such as a collection of users. To send notifications using the facade, pass all of the notifiable entities and the notification instance to the send method:
use Millions\Notifications\Facades\Notification; Notification::send($users, new InvoicePaid($invoice));
🌐 Routes
Get notifications
| Method | URI |
|---|---|
| GET | /notifications |
Mark as read
| Method | URI |
|---|---|
| PATCH | /notifications/read |
Delete notification
| Method | URI |
|---|---|
| DELETE | /notifications/{notificationId} |
Get notification settings
| Method | URI |
|---|---|
| GET | /settings/notifications |
Update notification setting
| Method | URI |
|---|---|
| PATCH | /settings/notifications/{notificationTypeId} |
Body Params
{
"status": true, // false
}
🎨 Customizing
First of all, create your own NotificationSettingController controllers and add the ManageNotificationSettings trait.
Second, modify the namespace of the Notification facade routes:
Notification::routesForSettings('App\Http\Controllers');
Custom request validations
The rules validationErrorMessages methods in the NotificationSettingController allows you override the default request validations:
<?php namespace App\Http\Controllers; use Millions\Notifications\ManageNotificationSettings; class NotificationSettingController extends Controller { use ManageNotificationSettings; /** * Get the notification settings validation rules. * * @return array */ protected function rules() { return [ 'status' => ['required', 'boolean'], ]; } /** * Get the notification settings validation error messages. * * @return array */ protected function validationErrorMessages() { return []; } }
Custom response
The sendResponse method in the NotificationSettingController allows you override the default response:
<?php namespace App\Http\Controllers; use Millions\Notifications\ManageNotificationSettings; class NotificationSettingController extends Controller { use ManageNotificationSettings; /** * Get the response for a successful listing notification settings. * * @param array $response * @return \Illuminate\Http\JsonResponse */ protected function sendResponse($response) { return response()->json($response); } }
Custom guards
The guard method in the NotificationSettingController allows you override the default guard:
<?php namespace App\Http\Controllers; use Millions\Notifications\ManageNotificationSettings; class NotificationSettingController extends Controller { use ManageNotificationSettings; /** * Get the guard to be used during notifications management. * * @return \Illuminate\Contracts\Auth\StatefulGuard */ protected function guard() { return auth('admin')->guard(); } }
🚸 Contributing
You are welcome to contribute to this project, but before you do, please make sure you read the contribution guide.
🔒 License
MIT
williamcruzme/laravel-notification-settings 适用场景与选型建议
williamcruzme/laravel-notification-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.32k 次下载、GitHub Stars 达 30, 最近一次更新时间为 2019 年 11 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notification」 「laravel」 「Settings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 williamcruzme/laravel-notification-settings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 williamcruzme/laravel-notification-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 williamcruzme/laravel-notification-settings 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Persistent settings package for Laravel framework.
This package makes it easy to send notifications via AfricasTalking with Laravel
A Zend Framework module to quickly and easily set PHP settings.
Settings Card for Laravel Nova.
Apple Push Notification & Feedback Provider
Throttle notifications on a per-channel basis
统计信息
- 总下载量: 10.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 30
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-13