Package Data | |
---|---|
Maintainer Username: | czim |
Maintainer Contact: | coen@pxlwidgets.com (Coen Zimmerman) |
Package Create Date: | 2016-03-20 |
Package Last Update: | 2019-10-29 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:16:28 |
Package Statistics | |
---|---|
Total Downloads: | 66,180 |
Monthly Downloads: | 824 |
Daily Downloads: | 59 |
Total Stars: | 5 |
Total Watchers: | 2 |
Total Forks: | 2 |
Total Open Issues: | 1 |
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.
Laravel | Package :----------------|:-------- 5.7.x and older | 1.0 5.8 and up | 1.1
Listify is great, but has a few shortcomings:
private
methods and properties, making it impossible to use Listify with flexible inheritance approaches.null
-scope as taking an item out of a list.Via Composer
$ composer require czim/laravel-listify
For general functionality the original Listify interface is largely the same. For reference, see the original documentation.
Some exceptions apply:
callable
scope, which may return any string to be used in a (raw) where
clause. The original limitations to Listify string scopes apply. However, null
is now an acceptable scope that will keep or remove the record from any list (its position
will remain NULL
).Although it is not required, you may make models that use the trait implement the ListifyInterface
for your own purposes.
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.
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).
Please see CONTRIBUTING for details.
Obviously, the main credits for anything to do with Listify go to:
The MIT License (MIT). Please see License File for more information.