williamcruzme/laravel-notification-settings 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 Laravel GitHub


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 我们能提供哪些服务?
定制开发 / 二次开发

基于 williamcruzme/laravel-notification-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10.32k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 30
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 30
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-13