PHPackages                             czim/laravel-listify - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. czim/laravel-listify

ActiveLibrary[Database &amp; ORM](/categories/database)

czim/laravel-listify
====================

Turns any model into a list. Rebuild of the popular Lookitsatravis Listify package.

2.0.3(6y ago)576.9k↓26.8%2[1 issues](https://github.com/czim/laravel-listify/issues)4MITPHPPHP &gt;=7.1.3CI failing

Since Mar 21Pushed 6y ago1 watchersCompare

[ Source](https://github.com/czim/laravel-listify)[ Packagist](https://packagist.org/packages/czim/laravel-listify)[ Docs](https://github.com/czim/laravel-listify)[ RSS](/packages/czim-laravel-listify/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (16)Used By (4)

Laravel Listify
===============

[](#laravel-listify)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ebccc9581c0dcdc512fbc59eda5d390fec3dadffc7654097a7421f426daa153b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f637a696d2f6c61726176656c2d6c6973746966792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/czim/laravel-listify)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/e169de386d81ffd2185b9e88ab82d94dbd60902f3d6db0f952a0d87a2153295d/68747470733a2f2f7472617669732d63692e6f72672f637a696d2f6c61726176656c2d6c6973746966792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/czim/laravel-listify)[![Latest Stable Version](https://camo.githubusercontent.com/0e849f1beb60fab0a56b67a25e719dd7103c533e0f5c83dc0f1df7c908a27e4d/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f637a696d2f6c61726176656c2d6c6973746966792e737667)](https://packagist.org/packages/czim/laravel-listify)[![SensioLabsInsight](https://camo.githubusercontent.com/bd302550564b501bf49b731bf117c14a97a262b76f9b01ed44bf12ca2ffa302b/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f37643830623866612d353634372d343063362d623562622d6439353833333938643132382f6d696e692e706e67)](https://insight.sensiolabs.com/projects/7d80b8fa-5647-40c6-b5bb-d9583398d128)

This is a rebuild (from scratch) of [Lookitsatravis' Listify](https://github.com/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
---------------------

[](#version-compatibility)

LaravelPackage5.7 and older1.05.8 - 5.91.16.0 and up2.0Changelog
---------

[](#changelog)

[View the changelog](CHANGELOG.md).

Why?
----

[](#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 `private` methods 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
-------

[](#install)

Via Composer

```
$ composer require czim/laravel-listify
```

Usage
-----

[](#usage)

For general functionality the original Listify interface is largely the same. For reference, see [the original documentation](https://github.com/lookitsatravis/listify).

Some exceptions apply:

- You may now use a `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`).
- 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
-------------------------------------

[](#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
--------------------------

[](#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
-----

[](#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
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Coen Zimmerman](https://github.com/czim)
- [All Contributors](../../contributors)

Obviously, the main credits for anything to do with Listify go to:

- [Travis Vignon](https://github.com/lookitsatravis)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~101 days

Recently: every ~49 days

Total

14

Last Release

2393d ago

Major Versions

0.9.6 → 1.0.02016-09-19

1.1.1 → 2.0.02019-09-21

PHP version history (2 changes)0.9.1PHP &gt;=5.4.0

1.1.0PHP &gt;=7.1.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/1657b09521b6030fe32d864a493ded8b1dbbdf737ef3772135dfc123cea34767?d=identicon)[czim](/maintainers/czim)

---

Top Contributors

[![czim](https://avatars.githubusercontent.com/u/11831617?v=4)](https://github.com/czim "czim (8 commits)")

---

Tags

eloquent-modelslaravel-packagelistifymodeleloquentlistposition

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/czim-laravel-listify/health.svg)

```
[![Health](https://phpackages.com/badges/czim-laravel-listify/health.svg)](https://phpackages.com/packages/czim-laravel-listify)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[prettus/l5-repository

Laravel 5|6|7|8|9|10|11|12 - Repositories to the database layer

4.2k10.8M145](/packages/prettus-l5-repository)[spatie/laravel-translatable

A trait to make an Eloquent model hold translations

2.4k23.0M413](/packages/spatie-laravel-translatable)[spatie/eloquent-sortable

Sortable behaviour for eloquent models

1.5k22.9M268](/packages/spatie-eloquent-sortable)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[nicolaslopezj/searchable

Eloquent model search trait.

2.0k2.7M35](/packages/nicolaslopezj-searchable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
