PHPackages                             larsjanssen6/increment-decrement - 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. larsjanssen6/increment-decrement

ActiveLibrary

larsjanssen6/increment-decrement
================================

Simple ways of incrementing/decrementing and sorting rows

v2.0(9y ago)447MITPHPPHP ^7.0

Since Mar 3Pushed 8y agoCompare

[ Source](https://github.com/larsjanssen6/increment-decrement)[ Packagist](https://packagist.org/packages/larsjanssen6/increment-decrement)[ Docs](https://github.com/larsjanssen6/increment-decrement)[ RSS](/packages/larsjanssen6-increment-decrement/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (3)Versions (6)Used By (0)

Laravel 5.4 sorting rows like a boss
====================================

[](#laravel-54-sorting-rows-like-a-boss)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![StyleCI](https://camo.githubusercontent.com/ef4380f818da26ebd9b2d70628a80f6107892c8344dd697e99dc6bafe600e08c/68747470733a2f2f7374796c6563692e696f2f7265706f732f38333830363735342f736869656c64)](https://styleci.io/repos/83806754)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/40e1503a437b7d31e48ffd9f18cdc4e4e09db012446ccc103b734994e1c6b26a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c6172736a616e7373656e362f696e6372656d656e742d64656372656d656e742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/larsjanssen6/increment-decrement/?branch=master)[![Build Status](https://camo.githubusercontent.com/ef99661812b91b3a26970d6eed2effb4df0858f40a1b4b3074b8dda25a7fd826/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c6172736a616e7373656e362f696e6372656d656e742d64656372656d656e742f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/larsjanssen6/increment-decrement/build-status/master)

This Laravel &gt;=5.4 package allows you to sort your rows very easy. You can play with the rows in a lot of ways.

Example:

[![demo](screenshots/Sort.gif)](screenshots/Sort.gif)

Once installed you can do the following:

```
Order::increment($model);
Order::decrement($model);
Order::toFirst($model);
Order::toLast($model);
Order::toMiddle($model);
Order::delete($model);
Order::switchModels($model1, $model2);
Order::switchIndexes($model, $index1, $index2);

```

The model (table) you want to sort needs a sort column. You can specifiy your column in the `increment-decrement` located in `config/increment-decrement.php`. Here you can set a

```
order_column_name

```

The default `order_column_name` is obviously `order`.

Install
=======

[](#install)

You can install the package via composer:

```
$ composer require larsjanssen6/increment-decrement
```

This `service provider` must be installed.

```
// config/app.php
'providers' => [
    ...
    LarsJanssen\IncrementDecrement\IncrementDecrementServiceProvider::class,
];
```

This package has a facade. Add it to the aliases array:

```
// config/app.php
'aliases' => [
    ...
    'Order' => LarsJanssen\IncrementDecrement\OrderFacade::class,
]

```

You can publish the config-file with:

```
php artisan vendor:publish --provider="LarsJanssen\IncrementDecrement\IncrementDecrementServiceProvider" --tag="config"

```

This is the contents of the published config file:

```
return [
	'order_column_name' => 'order',

	"first_one_can_increment" => true,

	"last_one_can_decrement" => true
];

```

Usage
=====

[](#usage)

First add an `integer` column to the table (migration) you want to sort. Then `migrate` again. Specify the column you have added in the config file `config/increment-dicrement` in `order_column_name`.

Then you can use the `Order` facade almost everywhere.

Example:

Make a migration with a column that's going to sort:

```
public function up()
{
    Schema::create('forum', function (Blueprint $table) {
	    $table->increments('id');
	    $table->string('name');
	    $table->integer('order');
    });
}

```

Add the column to the config file:

```
'order_column_name' => 'order',

```

Then in my `ForumController.php`:

```
use Order;

public function increment(Forum $forum)
{
    Order::increment($forum);
}

.....

```

The `first_one_can_increment` and `last_one_can_decrement` can be set in the config file to determine if the last and first row can increment/decrement.

Do not forget to increment the order column (or what you have specified in the config file) when you create a new record. For example:

```
return Forum::create([
    'name'          => $request->name,
    'description'   => $request->description,
    'order'         => Forum::all()->max('order') + 1
]);

```

Result in my own project:

[![demo](screenshots/Forum.gif)](screenshots/Forum.gif)

Require
=======

[](#require)

Laravel 5.4 &gt;=

Php 7.0 &gt;=

Testing
-------

[](#testing)

You can run the tests with:

```
vendor/bin/phpunit
```

Contribute
----------

[](#contribute)

I would love to hear your ideas to improve my code style and conventions. Feel free to contribute.

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity62

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 ~1 days

Total

5

Last Release

3354d ago

Major Versions

v1.2 → v2.02017-03-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/a4d9aa4c5839226600575626a8f1b03145547f55180fc96e6be1705ea9471590?d=identicon)[larsjanssen](/maintainers/larsjanssen)

---

Top Contributors

[![larsjanssen6](https://avatars.githubusercontent.com/u/7254997?v=4)](https://github.com/larsjanssen6 "larsjanssen6 (35 commits)")

---

Tags

laravelincrementDecrementLars JanssenIncreDecre

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/larsjanssen6-increment-decrement/health.svg)

```
[![Health](https://phpackages.com/badges/larsjanssen6-increment-decrement/health.svg)](https://phpackages.com/packages/larsjanssen6-increment-decrement)
```

###  Alternatives

[maher/laravel-counters

management for counters in laravel system

4511.2k](/packages/maher-laravel-counters)[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

394388.0k5](/packages/rtconner-laravel-likeable)[hemp/presenter

Easy Model Presenters in Laravel

247592.6k1](/packages/hemp-presenter)[poing/earmark

Laravel package to generate values in a unique and customizable series.

10712.9k](/packages/poing-earmark)[slowlyo/owl-admin

基于 laravel、amis 开发的后台框架~

61214.2k26](/packages/slowlyo-owl-admin)

PHPackages © 2026

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