{"id":13396098,"url":"https://github.com/lookitsatravis/listify","last_synced_at":"2025-03-13T22:31:42.391Z","repository":{"id":55589369,"uuid":"13445373","full_name":"lookitsatravis/listify","owner":"lookitsatravis","description":"Turn any Eloquent model into a list!","archived":true,"fork":false,"pushed_at":"2021-08-02T14:39:03.000Z","size":248,"stargazers_count":134,"open_issues_count":0,"forks_count":17,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-09-23T02:07:37.584Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://lookitsatravis.github.io/listify/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lookitsatravis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-09T15:01:28.000Z","updated_at":"2024-06-26T08:22:25.000Z","dependencies_parsed_at":"2022-08-15T03:50:28.271Z","dependency_job_id":null,"html_url":"https://github.com/lookitsatravis/listify","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookitsatravis%2Flistify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookitsatravis%2Flistify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookitsatravis%2Flistify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookitsatravis%2Flistify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lookitsatravis","download_url":"https://codeload.github.com/lookitsatravis/listify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243493854,"owners_count":20299726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:00:40.082Z","updated_at":"2025-03-13T22:31:42.075Z","avatar_url":"https://github.com/lookitsatravis.png","language":"PHP","funding_links":[],"categories":["Popular Packages"],"sub_categories":[],"readme":"# Listify (Inactive)\n\nTurn any Eloquent model into a list!\n\n| :zap:        Inactivity Notice ⚠️   |\n|-----------------------------------------|\n\nThanks for your interest. I no longer use PHP or Laravel and do not have the bandwidth to maintain this package.\n\n## Description\n\n`Listify` provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a `position` column defined as an integer on the mapped database table. `Listify` is an Eloquent port of the highly useful Ruby gem `acts_as_list` (https://github.com/swanandp/acts_as_list).\n\n[![Build Status](https://travis-ci.org/lookitsatravis/listify.svg?branch=master)](https://secure.travis-ci.org/lookitsatravis/listify)\n[![Coverage Status](https://coveralls.io/repos/lookitsatravis/listify/badge.png)](https://coveralls.io/r/lookitsatravis/listify)\n\n[![Latest Stable Version](https://poser.pugx.org/lookitsatravis/listify/v/stable.png)](https://packagist.org/packages/lookitsatravis/listify)\n\n* [Requirements](#requirements)\n* [Installation](#installation)\n* [Quick Start](#quickstart)\n* [Overview](#overview)\n* [Configuration](#configuration)\n* [Notes](#notes)\n* [Future Plans](#futureplans)\n* [Contributing](#contributing)\n* [Copyright](#copyright)\n\n\n## Requirements\n* `Listify` currently requires php \u003e= 5.5 (`Listify` is implemented via the use of traits).\n* Laravel 5.0 or higher\n\n\u003e For use with Laravel 4, please use version 1.0.6.\n\n## Installation\n`Listify` is distributed as a composer package, which is how it should be used in your app.\n\nInstall the package using Composer.  Edit your project's `composer.json` file to require `lookitsatravis/listify`.\n\n```js\n  \"require\": {\n    \"laravel/framework\": \"~5.0\",\n    \"lookitsatravis/listify\": \"~1.2\"\n  }\n```\n\nOnce this operation completes, the final step is to add the service provider. Open `app/config/app.php`, and add a new item to the providers array.\n\n```php\n    'Lookitsatravis\\Listify\\ListifyServiceProvider'\n```\n\nOptionally, you can define an alias to the `Listify` trait. Open `app/config/app.php`, and add a new item to the aliases array.\n\n```php\n    'Listify' =\u003e 'Lookitsatravis\\Listify\\Listify'\n```\n\n## Quickstart\n\nFirst things first, you'll need to add a column to store the position. From the command line, use the migration generator:\n\n```php\nphp artisan listify:attach {table_name} {position_column_name}\nphp artisan migrate\n```\n\n\u003e `{table_name}` is a required argument. `{position_column_name}` is optional and the default value is \"position\".\n\nThen, in your model:\n\n```php\nclass User extends Eloquent\n{\n    use \\Lookitsatravis\\Listify\\Listify;\n\n    public function __construct(array $attributes = array(), $exists = false) {\n\n        parent::__construct($attributes, $exists);\n\n        $this-\u003einitListify();\n    }\n}\n```\n\n\u003e Make sure that the `initListify()` method is called *after* `parent::__construct()` of your model.\n\nThat's all it takes to get access to the `Listify` hotness.\n\n## Overview\n\n### Instance Methods Added To Eloquent Models\n\nYou'll have a number of methods added to each instance of the Eloquent model to which `Listify` is added.\n\nIn `Listify`, \"higher\" means further up the list (a lower `position`), and \"lower\" means further down the list (a higher `position`). That can be confusing, so it might make sense to add tests that validate that you're using the right method given your context.\n\n#### Methods That Change Position and Reorder List\n\n- `eloquentModel.insertAt(2)`\n- `eloquentModel.moveLower()` will do nothing if the item is the lowest item\n- `eloquentModel.moveHigher()` will do nothing if the item is the highest item\n- `eloquentModel.moveToBottom()`\n- `eloquentModel.moveToTop()`\n- `eloquentModel.removeFromList()`\n\n#### Methods That Change Position Without Reordering List Immediately\n###### Note: a changed position will still trigger updates to other items in the list once the model is saved\n\n- `eloquentModel.incrementPosition()`\n- `eloquentModel.decrementPosition()`\n- `eloquentModel.setListPosition(3)`\n\n#### Methods That Return Attributes of the Item's List Position\n- `eloquentModel.isFirst()`\n- `eloquentModel.isLast()`\n- `eloquentModel.isInList()`\n- `eloquentModel.isNotInList()`\n- `eloquentModel.isDefaultPosition()`\n- `eloquentModel.higherItem()`\n- `eloquentModel.higherItems()` will return all the items above `eloquentModel` in the list (ordered by the position, ascending)\n- `eloquentModel.lowerItem()`\n- `eloquentModel.lowerItems()` will return all the items below `eloquentModel` in the list (ordered by the position, ascending)\n\n##Configuration\n\nThere are a few configuration options available. You'll need to pass these in as an array argument for `initListify()` in your model's constructor. Here are the options:\n\n- `top_of_list` sets the integer position for the top of the list (default: `1`).\n- `column` sets the name of your position column that you chose during installation (default: `'position'`).\n- `add_new_at` sets the name of your position column that you chose during installation (default: `'bottom'`, options: `'top'` or `'bottom'`).\n- `scope` allows you to scope the items in your list. This one requires a bit of elaboration. There are three posible values accepted:\n    - `string`\n    - `Illuminate\\Database\\Eloquent\\Relations\\BelongsTo` object\n    - `Illuminate\\Database\\Query\\Builder` object\n\n***\n\n###String\n\nIf `string` is passed in, a raw string is passed in as a `whereRaw` to the scope. This allows you to do something like `'custom_foreign_key = 42'` and have all of the items scoped to that result set. You can pass as complicated of a where clause as you want, and it will be passed straight into each DB operation.\n\nExample:\n\n```php\nclass User extends Eloquent\n{\n    use \\Lookitsatravis\\Listify\\Listify;\n\n    public function __construct(array $attributes = array(), $exists = false) {\n\n        parent::__construct($attributes, $exists);\n\n        $this-\u003einitListify([\n            'scope' =\u003e 'answer_to_ltuae = 42'\n        ]);\n    }\n}\n```\n\nResults in a scope of:\n\n`WHERE answer_to_ltuae = 42`\n\n***\n\n###Illuminate\\Database\\Eloquent\\Relations\\BelongsTo\n\nIf `Illuminate\\Database\\Eloquent\\Relations\\BelongsTo` is passed in, `Listify` will match up the foreign key of the scope to the value of the corresponding foreign key of the model instance.\n\nExample:\n\n```php\nclass ToDoListItem extends Eloquent\n{\n    use \\Lookitsatravis\\Listify\\Listify;\n\n    public function __construct(array $attributes = array(), $exists = false) {\n\n        parent::__construct($attributes, $exists);\n\n        $this-\u003einitListify([\n            'scope' =\u003e $this-\u003etoDoList()\n        ]);\n    }\n\n    public function toDoList()\n    {\n        $this-\u003ebelongsTo('ToDoList');\n    }\n}\n```\n\nResults in a scope of:\n\n`WHERE to_do_list_id = {{value of toDoListItem.to_do_list_id}}`\n\n***\n\n###Illuminate\\Database\\Query\\Builder\n\nAnd lastly, if `Illuminate\\Database\\Query\\Builder` is passed in, `Listify` will extract the where clause of the builder and use it as the scope of the `Listify` items. This scope type was added in an attempt to keep parity between the `acts_as_list` version and `Listify`; **however, due to differences in the languages and in ActiveRecord versus Eloquent, it is a limited implementation so far and needs impovement to be more flexible and secure. This is a big limitation and will be the first thing addressed in upcoming releases.**\n\nThis one is tricky, because in order for it to work the query objects `where` array is prepared with the bindings *outside of PDO* and then passed in as a raw string. So, please keep in mind that this route can open your application up to abuse if you are not careful about how the object is built. If you use direct user input, please sanitize the data before using this as a scope for `Listify`.\n\nExample:\n\n```php\nclass ToDoListItem extends Eloquent\n{\n    use \\Lookitsatravis\\Listify\\Listify;\n\n    public function __construct(array $attributes = array(), $exists = false) {\n\n        parent::__construct($attributes, $exists);\n\n        $this-\u003einitListify([\n            'scope' =\u003e DB::table($this-\u003egetTable())-\u003ewhere('type', '=', 'Not A List of My Favorite Porn Videos')\n        ]);\n    }\n}\n```\n\nResults in a scope of:\n\n`to_do_list_items.type = 'Not A List of My Favorite Porn Videos'`\n\n***\n\n### Changing the configuration\n\nYou may also change any configuration value during runtime by using `$this-\u003esetListifyConfig('key', 'value');`. For example, to change the scope, you can do this:\n\n```php\n$this-\u003esetListifyConfig('scope', 'what_does_the_fox_say = \"ring ding ding ding\"');\n```\n\nWhen an update is processed, the original scope will be used to remove the record from that list, and insert it into the new list scope. *Be careful here*. Changing the configuration during processing can have unpredictable effects.\n\n## Notes\n\nAll `position` queries (select, update, etc.) inside trait methods are executed without the default scope, this will prevent nasty issues when the default scope is different from `Listify` scope.\n\nThe `position` column is set after validations are called, so you should not put a `presence` validation on the `position` column.\n\n## Future Plans\n\n- Add support for using a closure as a scope\n- Update `Illuminate\\Database\\Query\\Builder` scope to be more secure and flexible\n- Additional features for the install command. Things like:\n    - update the model with trait automatically (including init method in constructor)\n    - generate (or add to) a controller with actions for each public method for `Listify`, including adding necessary routes. This would make it easy to, say, call something like `http://localhost:8000/foos/1/move_lower` through an AJAX-y front end.\n\nAside from that, I hope to just keep in parity with the Ruby gem `acts_as_list` (https://github.com/swanandp/acts_as_list) as necessary.\n\n## Contributing to `Listify`\n\n- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet\n- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it\n- Fork the project\n- Start a feature/bugfix branch\n- Commit and push until you are happy with your contribution\n- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.\n- Please try not to mess with the Composer.json, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.\n- I would recommend using Laravel 5.0 and higher for testing the build before a pull request.\n\n## Copyright\n\nCopyright (c) 2013-2017 Travis Vignon, released under the MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flookitsatravis%2Flistify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flookitsatravis%2Flistify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flookitsatravis%2Flistify/lists"}