承接 technovistalimited/notific 相关项目开发

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

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

technovistalimited/notific

Composer 安装命令:

composer require technovistalimited/notific

包简介

Laravel simple, static and minimal notification system

README 文档

README

Notific is a simple, and minimal, static notification system for Laravel. It stores notification data based on user_id, and fetch notifications for the user_id. It's not that feature rich.

The package has no UI, it just a database based cached data-driven mechanism of organized methods. You have to build you own UI.

GitHub release GitHub license Laravel package

License: GPL-2.0+
Requires: Laravel 5.8
Tested up to: Laravel 8.x
Developers: Mayeenul Islam, Nazmul Hasan

_________NOTICE_________
The package is developed for the organization's internal use only. If it helps you, that's why it's here. We might not support the package full throttle. But bug reports are welcome.

Table of Contents

Features

  • Database table creation using migration
  • Store notifications into the database
  • Fetch notifications from the database
  • Store and fetch any types of additional information for notification with metadata
  • Cached data to save some valuable resources - configurable

Features that are not present:

  • Event listener and real-time notification (but you can easily extend into those)

Installation

Step 1: Download & Setup

Open up the command console on the root of your app and run:

composer require technovistalimited/notific

Providers array

Add the following string to the config/app.php under providers array:

Technovistalimited\Notific\NotificServiceProvider::class,

Aliases array

Add the following line to the config/app.php under aliases array:

'Notific' => Technovistalimited\Notific\Facades\Notific::class,

Step 2: Publish the Necessary files

Make the configuration and migration files ready first; in the command console, type and hit enter:

php artisan vendor:publish --tag=notific

Step 3: Make tables ready

Open up the command console on the root of your app and run the migrations:

php artisan migrate

Configuration

Change configuration in config/notific.php.

Cache status

Set whether to use the cache or not, under 'cache' => ['is_cache']. Accepted value: true (enabled), false (disabled)
Default: true - enabled

Cache time

Change the time under 'cache' => ['cache_time']. Accepted value: any positive integer to denote seconds.
Default: 10 minutes

API: How to use

If you defined the helper class correctly, the package is easy to use:

Store notification

To store notification, simply place the following method where you want to plug it into. The method will also clear the cache for the user to update the notification history.

Notific::notify( $userId, $message, $notificationType, $metaData, $createdBy );

$userID : integer/array
User ID or array of user IDs to notify.

$message : string
The message with which you want to notify with.

$notificationType : string : (optional)
The notification type if you have any, other than notification.
default: 'notification'

$metaData : integer/string/array : (optional)
Whatever additional information you want to pass with. Whether pass them as integer, string or as an array.
default: empty

$createdBy : integer : (optional)
If you want to keep trace who issued the notification.
default: empty

Get notifications

Get the notifications by user ID.

Notific::getNotifications( $userId, $arguments );

$userID : integer
User ID for which to fetch the notifications.

$arguments : array : (optional)
Array of Query parameters. default: array() - fetch notifications based on default settings

$read_status : string
The notification read status. Accepts: 'all', 'read', 'unread'.
default: 'all'

$order : string
Designates ascending or descending order of notifications. Accepts 'ASC', 'DESC'.
default: 'DESC'

$orderby : string
Sort retrieved posts by parameter. Single option can be passed. Accepts any valid column name from db table.
default: 'created_at'

$paginate : boolean
Whether to enable pagination or not.
default: false - pagination DEactivated

$items_per_page : integer
Fetch the number of items. Accepts any positive integer.
default: -1 - fetch everything

Get notification count

Get the total count of notifications by user ID.

Notific::getNotificationCount( $userId, $status );

$userID : integer
User ID for which to fetch the notifications.

$status : string : (optional)
The notification read status. Accepts: 'all', 'read', 'unread'.
default: all - fetch all the notification count

Mark notification as read

Mark the notification as read when actually they are. You might need AJAX to mark them read on the fly.

Notific::markNotificationRead( $userId, $notificationId );

$userID : integer
User ID to mark the notification as read for.

$notificationId : integer : (optional)
If you want to mark each of the notification as read, pass the notification ID
default: empty - mark all as read

Examples

01. Create a notification

With the following examples, a user with the ID 21 will be notified accordingly:

// Notified with a simple message.
Notific::notify( 21, 'Your application submitted.' ) );

// Notified with a message and date.
Notific::notify( 21, sprintf( 'Your application submitted on %s is approved.', date('d F Y') ) );

// Notified with a different type of notification.
Notific::notify( 21, 'Your application submitted.', 'message' ) );

// Notified with some meta data incorporated.
Notific::notify( 21, 'Your application is approved. Click to see it.', 'notification', array('link' => 'http://link.to/the/application/' ) ) );

// Notified with someone who (with ID 8) assigned the notification
Notific::notify( 21, 'Your application submitted.', 'notification', '', 8 ) );

// Notify multiple users (with ID 21, 4, and 5) at a time
Notific::notify( [21, 4, 5], 'An application is submitted. Please check.' );

02. Get notifications

With the following examples, we're fetching the notifications assigned to a user with ID 21:

// Get all the notifications.
Notific::getNotifications( 21 );

// Get unread notifications only.
Notific::getNotifications( 21, array( 'read_status' => 'unread' ) );

// Get read notifications only.
Notific::getNotifications( 21, array( 'read_status' => 'read' ) );

// Get read notifications and maximum 10 of them only.
Notific::getNotifications( 21, array( 'read_status' => 'all', 'items_per_page' => 10 ) );

// Get all notifications and paginate them to 50 per page only.
Notific::getNotifications( 21, array( 'paginate' => true, 'items_per_page' => 50 ) );

03. Get notification count

With the following examples, we're fetching the count of notifications assigned to a user with ID 21:

// Get all notifications of the user ID 21.
Notific::getNotificationCount( 21 );
Notific::getNotificationCount( 21, 'all' );

// Get only the 'unread' notifications of the user ID 21.
Notific::getNotificationCount( 21, 'unread' );

// Get only the 'read' notifications of the user ID 21.
Notific::getNotificationCount( 21, 'read' );

04. Mark notification as read

// Mark all the notifications as 'read' for the user with ID 21.
Notific::markNotificationRead( 21 );

// Mark notification number 56 as 'read' for the user with ID 21.
Notific::markNotificationRead( 21, 56 );

05. Maybe Unserialize

Adopted from WordPress, this function can detect whether to unserialize a string or not and serialize, if it's a serialized data. If you make custom methods, you might need to convert the serialized meta data back into array - this method will help you then.

// Unserialize if serialized.
Notific::maybeUnserialize( $string );

Contributions

Any bug report is welcome. We might not support the package as you might require. But we will definitely try to fix the bugs as long as they meet our leisure.

If you want to contribute code, feel free to add Pull Request.

Uninstallation

  • Search the whole project of any declaration of Notific::, and remove the functions from the source, or comment them out. Otherwise, they will generate a fatal error after uninstallation.
  • Open config/app.php and remove the line ...NotificServiceProvider::class under providers and aliases array.
  • Remove the configuration file notific.php in config/notific.php
  • Remove the notific migration files from database/migrations/
  • Delete the two database tables manually (as the package is not released): table:notifications, and table:user_notifications

Now, open up the command console, and type:

composer remove technovistalimited/notific

You are done!

Credits

All the credit goes to the almighty God first. Thanks to Mr. Amiya Kishore Saha who let both of us make our first Laravel package. Thanks to Mr. Kamrul Hasan for reviewing the progress and suggesting his ideas. And thanks to TechnoVista Limited for supporting the initiative. Thanks to Notifynder - a Laravel notification package available at Packagist from Fabrizio - we followed them to learn. Thanks to WordPress - a GPL licensed web framework - we took some of their code thankfully.

technovistalimited/notific 适用场景与选型建议

technovistalimited/notific 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 242 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「notification」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 technovistalimited/notific 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 technovistalimited/notific 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2021-04-07