承接 audentio/laravel-notifications 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

audentio/laravel-notifications

Composer 安装命令:

composer require audentio/laravel-notifications

包简介

Base notifications and notification preferences system for Audentio platforms.

README 文档

README

Tests Latest Version on Packagist PHP Version License

Notifications and notification preference system for Audentio Laravel platforms. Provides a database-backed notification preference system with per-channel defaults, per-tenant overrides, per-user overrides, a GraphQL API, and optional push notification support.

Requirements

Installation

composer require audentio/laravel-notifications

Publish and run the migrations:

php artisan vendor:publish --tag=audentio-notifications-config
php artisan migrate

Publish the model stubs:

php artisan vendor:publish --tag=audentio-notifications-models

Setup

1. Implement models

The published stubs in app/Models/ need to be wired up to your application. At minimum:

NotificationPreference — extend getDefaultUserNotificationPreferenceValue() if needed. The getName() method must return a human-readable label (typically from a translation key).

NotificationPreferenceGroup — same, getName() must be implemented.

UserNotificationPreference — no changes needed beyond the stub.

2. Add the trait to your User model

use Audentio\LaravelNotifications\Models\Interfaces\NotifiableUserInterface;
use Audentio\LaravelNotifications\Models\Traits\NotifiableUserTrait;

class User extends Model implements NotifiableUserInterface
{
    use NotifiableUserTrait;

    public function isEmailVerified(): bool
    {
        return $this->email_verified_at !== null;
    }
}

3. Create notification handlers

Extend AbstractNotification and implement getNotificationPreferenceId():

use Audentio\LaravelNotifications\Notifications\AbstractNotification;

class NewMessageNotification extends AbstractNotification
{
    public function getNotificationPreferenceId(): string
    {
        return 'newMessage';
    }

    public function toMail($notifiable): MailMessage
    {
        return (new MailMessage)->subject('New message');
    }
}

4. Seed preferences

Run your NotificationPreferencesAndGroupsTableSeeder after adding handlers. The seeder auto-discovers handlers and creates NotificationPreference records.

Notification Preference Hierarchy

User preferences follow a 3-level fallback (highest priority first):

Level Source Stored in
3 User override user_notification_preferences.disabled_channels
2 Tenant override App-provided via getNotificationPreferenceTenantDefaults()
1 Global default notification_preferences.default_disabled_channels

When no record exists at a level, the next level is used. An empty disabled_channels array means all channels are enabled.

Setting global defaults

Set default_disabled_channels when seeding a preference:

'streamGoLive' => [
    'available_channels' => ['notification', 'mail'],
    'default_disabled_channels' => ['mail'], // mail off by default for all users
],

Tenant-level overrides

Override getNotificationPreferenceTenantDefaults() on your User model to load tenant-specific defaults. This is called once per getUserNotificationPreferenceValues() call — load all tenant preferences in a single query:

public function getNotificationPreferenceTenantDefaults(): Collection
{
    $tenant = $this->getCurrentTenant();
    if (!$tenant) {
        return collect();
    }
    return TenantNotificationPreference::where('tenant_id', $tenant->id)->get();
}

Optional: Disable automatic migrations

If you manage migrations manually:

// In a service provider
LaravelNotifications::skipMigrations();

Optional: Push notifications

Enable push support in config/audentioNotifications.php:

'push_enabled' => true,
'push_handler_classes' => [
    'expo' => \Audentio\LaravelNotifications\PushHandlers\ExpoPushHandler::class,
    'fcm'  => \Audentio\LaravelNotifications\PushHandlers\FirebasePushHandler::class,
],

Run the additional push migrations:

php artisan migrate

Push subscriptions are managed via the routeNotificationForPush() method on your User model (provided by NotifiableUserTrait — override if needed).

GraphQL

The package auto-registers a GraphQL schema when audentio/laravel-graphql is present. Exposed types, queries, and mutations include:

  • Queries: notifications, notificationPreferenceGroups
  • Mutations: updateViewerNotificationPreferenceValue, dismissNotification, markReadNotification, markUnreadNotification, markReadAllNotifications, dismissAllNotifications
  • Types: NotificationPreference, NotificationPreferenceGroup, UserNotificationPreferenceValue, NotificationChannelEnum

Override individual types via graphQL_schema_overrides in the config.

To disable GraphQL registration:

LaravelNotifications::skipGraphQLSchema();

Testing

composer test

License

MIT

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固