stayallive/laravel-eloquent-observable
Composer 安装命令:
composer require stayallive/laravel-eloquent-observable
包简介
Register Eloquent model event listeners just-in-time directly from the model.
关键字:
README 文档
README
Register Eloquent model event listeners just-in-time directly from the model.
Using Observers can introduce a (significant) overhead on the application since they are usually registered in a service provider which results in every model in your application with a observer is "booted" a startup of the application even though the model is never touched in the request. This package aims to reduce that overhead by connecting listeners just-in-time whenever the Eloquent model is booted (first used) in the request. The event callbacks are also defined on the model itself keeping the code cleaner, althought this is my preference of course and if you disagree this might not be the package for you.
Note
Laravel 10.44 introduced the ObservedBy attribute which allows you to define the observer on the model itself which negates all the performance benefits of this package.
However this package still provides an alternative way to define the event handler methods on the model itself so might still be considered useful but using the ObservedBy attribute will solve the performance issue with registering the model observers inside a service provider.
Installation
composer require stayallive/laravel-eloquent-observable
Usage
Adding the Observable trait will ensure that the observable events are connected to the event handlers defined on the model.
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Stayallive\Laravel\Eloquent\Observable\Observable; class SomeModel extends Model { use Observable; // Event handlers are defined by `onEventName` where `EventName` is any valid Eloquent event (or custom event) // See a full list of Eloquent events: https://laravel.com/docs/9.x/eloquent#events public static function onSaving(self $model): void { // For example: $model->slug = str_slug($model->title); } }
Security Vulnerabilities
If you discover a security vulnerability within this package, please send an e-mail to Alex Bouma at alex+security@bouma.me. All security vulnerabilities will be swiftly
addressed.
License
This package is open-sourced software licensed under the MIT license.
stayallive/laravel-eloquent-observable 适用场景与选型建议
stayallive/laravel-eloquent-observable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40.92k 次下载、GitHub Stars 达 29, 最近一次更新时间为 2022 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「eloquent」 「observers」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 stayallive/laravel-eloquent-observable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stayallive/laravel-eloquent-observable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 stayallive/laravel-eloquent-observable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Eloquent model trait for translatable resource
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Help to manage meta data on Laravel Eloquent model
A package to cast json fields, each sub-keys is castable
Alfabank REST API integration
Auto-generate dummy data with realistic relationships per Model-like config classes
统计信息
- 总下载量: 40.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 29
- 点击次数: 25
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-28