czim/laravel-listify
Composer 安装命令:
composer require czim/laravel-listify
包简介
Turns any model into a list. Rebuild of the popular Lookitsatravis Listify package.
README 文档
README
This is a rebuild (from scratch) of Lookitsatravis' Listify for personal reasons. It uses the same interface as Listify, so switching from that to this package should not break anything.
Version Compatibility
| Laravel | Package |
|---|---|
| 5.7 and older | 1.0 |
| 5.8 - 5.9 | 1.1 |
| 6.0 and up | 2.0 |
Changelog
Why?
Listify is great, but has a few shortcomings:
- A very minor one is the code standard, which could IMHO do with some serious cleanup.
- More annoying are the heavy reliance on
privatemethods and properties, making it impossible to use Listify with flexible inheritance approaches. - Functionally, Listify is not suited for variable scopes. The belongs-to scope is too restrictive (no nullable foreign key columns), and any string-based scope is set inflexibly.
For my purposes, I require a callable scope that handles swapping scopes well and treats a
null-scope as taking an item out of a list.
Install
Via Composer
$ composer require czim/laravel-listify
Usage
For general functionality the original Listify interface is largely the same. For reference, see the original documentation.
Some exceptions apply:
- You may now use a
callablescope, which may return any string to be used in a (raw)whereclause. The original limitations to Listify string scopes apply. However,nullis now an acceptable scope that will keep or remove the record from any list (itspositionwill remainNULL). - You may now use nullable and null foreign keys for BelongsTo scopes. A record without the relevant foreign key will not be added to a list.
Although it is not required, you may make models that use the trait implement the ListifyInterface for your own purposes.
Differences with the original Listify
There is no attach artisan command supplied; you are expected to handle your position column migrations yourself.
The exceptions that do get thrown have been simplified. InvalidArgumentException, UnexpectedValueException and BadMethodCallException are thrown instead of custom exceptions.
Exceptions are no longer thrown for 'null scope' or 'null foreign key', since these are now expected and allowed. Models with an effective 'null scope' will now silently be excluded from lists.
Note that this package has been tested with the original listify PHPUnit tests and passes them where behavior has not intentionally changed.
Finally, this trait may be used with inheritance (because its base scope is protected rather than private). You can make a 'BaseListifyModel' and extend that to avoid code (or setup) duplication.
Dealing with global scopes
When using global scopes on a listified model, this may break expected functionality, especially when the global scope affects how the records are ordered. To deal with this, listify will check for a method to clean up the scope as required. To use this, simply add an implementation of the following method to your listified model class:
/** * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function cleanListifyScopedQuery($query) { // Return the query builder after applying the necessary cleanup // operations on it. In this example, a global scope ordering the // records by their position column is disabled by using unordered() return $query->unordered(); }
This method will be called any time that listify performs checks and operations on the model for which it needs access (and its own ordering).
To Do
- The way string (and QueryBuilder) scopes work is slightly strange. Adding new records that fall outside of the scope will be added with a position value. Those records are reported as being in a list, and odd things can happen when manipulating them.
Contributing
Please see CONTRIBUTING for details.
Credits
Obviously, the main credits for anything to do with Listify go to:
License
The MIT License (MIT). Please see License File for more information.
czim/laravel-listify 适用场景与选型建议
czim/laravel-listify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 78.75k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2016 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「model」 「list」 「position」 「eloquent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 czim/laravel-listify 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 czim/laravel-listify 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 czim/laravel-listify 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easily provide front-end sorting controls for SilverStripe lists
An IP address information display widget for Yii 2.0 with country flag and geo position info.
A block to display a list of links to child pages, or pages in current level
Adjacency List’ed Closure Table database design pattern implementation for Laravel. Includes restore of tree
FSi admin positionable bundle.
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
统计信息
- 总下载量: 78.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 17
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-21