coreproc/nova-notification-feed
Composer 安装命令:
composer require coreproc/nova-notification-feed
包简介
A Laravel Nova package that adds a notification feed in your Nova app.
README 文档
README
A Laravel Nova package that adds a notification feed in your Nova app and uses Laravel Echo and websockets to receive and broadcast notifications.
Installation
You can install the package into a Laravel app that uses Nova via composer:
composer require coreproc/nova-notification-feed
This package makes use of Laravel's database notification feature and Nova Echo to receive and broadcast notifications.
By using Nova Echo, we have a readily configured Laravel Echo instance in our JS.
Here are the suggested options for broadcasting/receiving using websockets:
Make sure that you already have any of these options set up and prepare your Laravel project to use it for broadcasting notifications.
You can find instructions about broadcasting in Laravel using the official documentation.
Follow the docs, make sure to run the following to get the notifications table if you have not done so already:
php artisan notifications:table
php artisan migrate
Before broadcasting any events, you will first need to register the App\Providers\BroadcastServiceProvider. In fresh Laravel applications, you only need to uncomment this provider in the providers array of your config/app.php configuration file. This provider will allow you to register the broadcast authorization routes and callbacks.
Make sure that you configure the correct environment variables in your .env file:
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=xxxxxxx
PUSHER_APP_KEY=xxxxxxx
PUSHER_APP_SECRET=xxxxxx
PUSHER_APP_CLUSTER=xxx
You will also need to ensure that you have added an authorization broadcast route in routes/channels.php:
Broadcast::channel('App.User.{id}', function ($user, $id) { return (int)$user->id === (int)$id; });
Receiving notifications will depend on your User model having the Notifiable trait. You can add the receivesBroadcastNotificationsOn to use a different channel name instead of the user model's namespace.
class User extends Authenticatable { use Notifiable; ... /** * The channels the user receives notification broadcasts on. * * @return string */ public function receivesBroadcastNotificationsOn() { return 'users.' . $this->id; } }
Finally, once you have ensured that this is set up, you will also need to override Nova's layout.blade.php. Create a layout file in resources/views/vendor/nova/layout.blade.php and copy the contents from vendor/laravel/nova/resources/views/layout.blade.php.
Add these two lines to the layout template:
// file: resources/views/vendor/nova/layout.blade.php
<!DOCTYPE html>
<html lang="en" class="h-full font-sans antialiased">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=1280">
<meta name="csrf-token" content="{{ csrf_token() }}">
@include('nova-echo::meta') <!-- INCLUDE THIS LINE HERE -->
<title>
...
<dropdown class="ml-auto h-9 flex items-center dropdown-right">
@include('nova::partials.user')
</dropdown>
@include('nova_notification_feed::notification_feed') <!-- AND THIS LINE HERE -->
...
You should now be able to see the notification bell on the top right of your Nova UI.
Usage
To broadcast notifications to your notification feed in the Nova app, you can make a notification class that sends notifications via database and broadcast. Here is an example notification class:
use Coreproc\NovaNotificationFeed\Notifications\NovaBroadcastMessage; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\BroadcastMessage; use Illuminate\Notifications\Notification; class TestNotification extends Notification { use Queueable; protected $level = 'info'; protected $message = ''; /** * Create a new notification instance. * * @param $level * @param $message */ public function __construct($level, $message = 'Test message') { $this->level = $level; $this->message = $message; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [ 'database', 'broadcast', ]; } /** * Get the array representation of the notification. * * @param mixed $notifiable * @return array */ public function toArray($notifiable) { return [ 'level' => $this->level, 'message' => $this->message, 'url' => 'https://coreproc.com', 'target' => '_self' ]; } /** * Get the broadcastable representation of the notification. * * @param mixed $notifiable * @return BroadcastMessage */ public function toBroadcast($notifiable) { return new NovaBroadcastMessage($this->toArray($notifiable)); } }
Nova Notification Feed relies on having three variables passed in the toArray() method of the notification class: level, message, and url, and an optional target (default: '_blank').
Additionally, you can use the NovaBroadcastMessage class in the toBroadcast() method to ensure that the format of the broadcast can be read by the frontend.
Roadmap
- Differentiate background color of a new notification
- Check if the URL is an JSON representation of a route
{ name: 'index', params: {} } - Better design?
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email chris.bautista@coreproc.ph instead of using the issue tracker.
Credits
About CoreProc
CoreProc is a software development company that provides software development services to startups, digital/ad agencies, and enterprises.
Learn more about us on our website.
License
The MIT License (MIT). Please see License File for more information.
coreproc/nova-notification-feed 适用场景与选型建议
coreproc/nova-notification-feed 是一款 基于 Vue 开发的 Composer 扩展包,目前已累计 49.36k 次下载、GitHub Stars 达 99, 最近一次更新时间为 2019 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notifications」 「nova」 「laravel」 「sidebar」 「Broadcast」 「notice board」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 coreproc/nova-notification-feed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 coreproc/nova-notification-feed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 coreproc/nova-notification-feed 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
A Laravel Nova Image field. you can paste or drag or chose an image
Captures outgoing SMS notifications
统计信息
- 总下载量: 49.36k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 99
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-30
