east/laravel-activityfeed
Composer 安装命令:
composer require east/laravel-activityfeed
包简介
Your Package Description here
README 文档
README
Install
composer require east/laravel-activityfeed
It is strongly recommended to have Laravel Backpack Pro version installed (https://backpackforlaravel.com/). The web interface for defining ruling and templates relies on Backpack and it will be hard to manage without it.
Important note about database
This extension relies heavily on users table and requires you to have a column called "admin". The users model is published to make it easier to edit columns and relationships if you have customised the database. Note though that
php artisan vendor:publish --force
will overwrite your changes to thisAf model. So you can change this model to extend your existing user class.
Screenshots
Run installer
php artisan af:install
Usage
Available command line commands
This will create a rule templates and corresponding template entries based on your entire database structure. Running it again will not overwrite anything, but will add any tables that were not there before.
php artisan af:discover_rules
Template, rule etc. handling interfaces is based on Laravel Backpack. It's not included with the ActivityFeed package.
php artisan af:install_backpack
Individual notifications
Best way to use ActivityFeed is to extend your base model with ActivityFeedBaseModel. This allows the rules to hook into database events directly based on the rules that are tied to database tables. You can also create notification directly. You still need to have a rule for this purpose, as rule defines the template.
AfNotify::setTemplate('template-slug') // mandatory ->addChannel(['email']) // additional channels ->setSubject('New message') // optional, template defines this already ->setTarget('user') // default: user ->setUser(auth()->user()->id) // default: current user ->setDigest() // set to digest instead of notifying immediately ->setVars($array) // key-value replacement ->setObjects(['user' => $obj1, 'company' => $obj2]) // database objects ->add();
Model based triggering - rules
Rules are tied to events in particular database tables and include the following options:
- Table name
- Event (create, update, delete)
- If it's update, which column will trigger the update
- Change (any, based on rules)
- Column name
- Operator
- Value
In addition, you can create custom rules with PHP code. These go under app/ActivityFeed/Rules/. When you do the install, an example rule will be put in place.
Creators
In addition to manually defined rules that take care of the saving, you can also use a custom save class - these are called creators. The creators go under app/ActivityFeed/Creators/. When you do the install, an example creator will be put in place.
Targeting
Target should always be an individual user, regardless of whether it's shown on a feed or sent via some other channel(s). In addition target can be admin users. Whether a particular notification
This is where it gets slightly complicated. Let's say a database record modification/creation in Posts launches a notification event that should be targeted at certain group of users. Example database structure:
Posts
↓
Recipients (pivot)
↓
Recipient
↓
Users
As pivot records don't exist when creating the Posts, we will save this event to be created as a notification by the cron job. The difficult part is on mapping the relationship chain.
Templating
Templates are in Laravel Blade format and saved to database. Templates are fed with var replacement and data replacement. Idea is that you can dump data from your database record and it's relations directly to the template. So you would define it like this:
You have a new notification, click <a href="{{$url ?? ''}}">here</a> to read it.
So also this would work:
@if(isset($username) AND $username)) Hello {{$username}}! @endif You have a new notification, click <a href="{{$url ?? ''}}">here</a> to read it.
And this (provided you are sending the correct objects):
@if(isset($user->profile) AND $user->profile)) Hello {{$user->profile->name}}! @endif You have a new notification, click <a href="{{$url ?? ''}}">here</a> to read it.
The variable replacement happens at save time and is "blind" so you should adjust your templates accordingly.
Rules define targeting and channels.
Forking / messing with the models
As I'm lazy, I've used the excellent model generator from krlove. You can use it like this (adjust paths obviously):
php artisan krlove:generate:model --base-class-name='East\LaravelActivityfeed\Models\ActivityFeedBaseModel' --namespace='East\LaravelActivityfeed\Models\ActiveModels' --output-path=../vendor/east/laravel-activityfeed/src/Models/ActiveModels/ --table-name=af_events AfEventsModel php artisan krlove:generate:model --base-class-name='East\LaravelActivityfeed\Models\ActivityFeedBaseModel' --namespace='East\LaravelActivityfeed\Models\ActiveModels' --output-path=../vendor/east/laravel-activityfeed/src/Models/ActiveModels/ --table-name=af_rules AfRules php artisan krlove:generate:model --base-class-name='East\LaravelActivityfeed\Models\ActivityFeedBaseModel' --namespace='East\LaravelActivityfeed\Models\ActiveModels' --output-path=../vendor/east/laravel-activityfeed/src/Models/ActiveModels/ --table-name=af_categories AfCategories php artisan krlove:generate:model --base-class-name='East\LaravelActivityfeed\Models\ActivityFeedBaseModel' --namespace='East\LaravelActivityfeed\Models\ActiveModels' --output-path=../vendor/east/laravel-activityfeed/src/Models/ActiveModels/ --table-name=af_templates AfTemplatesModel php artisan krlove:generate:model --base-class-name='East\LaravelActivityfeed\Models\ActivityFeedBaseModel' --namespace='East\LaravelActivityfeed\Models\ActiveModels' --output-path=../vendor/east/laravel-activityfeed/src/Models/ActiveModels/ --table-name=af_notifications AfNotificationsModel
Rendering
Upon install we publish af.css to public css directory and it's included with the widgets. Alternatively you can copy it to resources/css/ and import it to your app.css. In this case make sure to set configuration option for not including the css with the widgets.
Include widgets
Available widgets:
- FeedWidget
- MenuWidget
- NotificationWidget
Understanding the flow
Model event
↓
Check rules
↓
Create event
↓
Cronjob (afpoll:run)
↓
Create notifications (uses mapping)
↓
Render and/or send notification
As pivot records don't exist when creating the Posts, we will save this event to be created as a notification by the cron job. The difficult part is on mapping the relationship chain.
Testing
Run the tests with:
vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email timo@east.fi instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
east/laravel-activityfeed 适用场景与选型建议
east/laravel-activityfeed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 546 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notifications」 「laravel」 「activity feed」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 east/laravel-activityfeed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 east/laravel-activityfeed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 east/laravel-activityfeed 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
A very simple activity logger to monitor the users of your website or application (for MongoDB)
A simple activity feed for laravel 5+
Captures outgoing SMS notifications
Laravel activity log viewer
A very simple logger to monitor the users' activities
统计信息
- 总下载量: 546
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-20





