PHPackages                             casperw/laravel-tidy-tables - 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. casperw/laravel-tidy-tables

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

casperw/laravel-tidy-tables
===========================

Structures your database columns nice and tidy.

1.0.1(7y ago)037MITPHP

Since Oct 9Pushed 7y ago1 watchersCompare

[ Source](https://github.com/casperwitting/laravel-tidy-tables)[ Packagist](https://packagist.org/packages/casperw/laravel-tidy-tables)[ Docs](https://github.com/casperw/laravel-tidy-tables)[ RSS](/packages/casperw-laravel-tidy-tables/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (6)Versions (5)Used By (0)

Laravel Tidy Tables
===================

[](#laravel-tidy-tables)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5b015e48c671e8a4baefd9dfa0a72672cb27bfa8061c9194d864121c6d7f84cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636173706572772f6c61726176656c2d746964792d7461626c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/casperw/laravel-tidy-tables)[![Total Downloads](https://camo.githubusercontent.com/62faaf8b4eaeafece3321bb5f4b8ee68b483f3488583b23b3b6161c0f25877a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636173706572772f6c61726176656c2d746964792d7461626c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/casperw/laravel-tidy-tables)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![StyleCI](https://camo.githubusercontent.com/f5180af4b39eec8b088d92ca9be57b697d1c6e29d0c20d81e2410beee718a548/68747470733a2f2f7374796c6563692e696f2f7265706f732f3135323239373039362f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/152297096)

This package provides a way to reorder the columns of all your existing database tables. The sorting algorithm will sort table columns in the following structure:

- Primary key
- Universally unique identifier
- Foreign keys
- Native columns
- Timestamps

Example
-------

[](#example)

For example, I've created a 'products' table. You might recognize the situation on the left, where the table became messy and unstructured.

The table on the right shows how the columns are grouped after running the tidy command.

[![Alt text](tidy-tables.jpg?raw=true "Tidy example")](tidy-tables.jpg?raw=true)

Installation
------------

[](#installation)

Via Composer

```
$ composer require casperw/laravel-tidy-tables --dev
```

Configuration
-------------

[](#configuration)

The defaults are set in config/laraveltidytables.php. Copy this file to your own config directory to modify the values. You can publish the config using this command:

```
$ php artisan vendor:publish --tag=laraveltidytables.config
```

The configuration file contains an array of fields, and an array of data types.

#### Available fields

[](#available-fields)

```
    /*
    |--------------------------------------------------------------------------
    | Fields
    |--------------------------------------------------------------------------
    |
    | The following fields are configurable and are used during
    | sorting of the configured database. Change these existing fields to your liking.
    | Note, that it's possible to add timestamps and change order to your liking.
    |
    */
    'fields' => [
        'primary_key' => 'id',
        'universally_unique_identifier' => 'uuid',
        'foreign_key_affix' => '_id',
        'timestamps' => [
            'deleted_at',
            'updated_at',
            'created_at',
        ],
    ],
```

#### Available data types

[](#available-data-types)

> **Note:** By default, the configuration supports laravel's default datatypes. Check if your database corrosponds with the default values, and change them if needed!

```
    /*
    |--------------------------------------------------------------------------
    | Data types
    |--------------------------------------------------------------------------
    |
    | Here are all the datatypes that are used by the sorting algoritm.
    | It's important to note that these values are based on laravel's default migration data types.
    | You might not use a CHAR(36) for uuid's in your configuration. Change these values if so.
    |
    */
    'data_types' => [
        'universally_unique_identifier' => 'CHAR(36)',
        'foreign_keys' => 'INTEGER UNSIGNED',
        'timestamps' => 'TIMESTAMP NULL'
    ]
```

Usage
-----

[](#usage)

The following command will sort all of your database's tables.

> **Note:** Always make sure to back-up your database first.

```
$ php artisan migrate --tidy
```

Change log
----------

[](#change-log)

Please see the [changelog](changelog.md) for more information on what has changed recently.

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

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

Total

2

Last Release

2771d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/15c44e7359f555985267df8e0b82af91b72549a51681b2253511f7a2c72ebf92?d=identicon)[casperw](/maintainers/casperw)

---

Top Contributors

[![casperwitting](https://avatars.githubusercontent.com/u/14952001?v=4)](https://github.com/casperwitting "casperwitting (39 commits)")

---

Tags

laravelstructuretablesortingcolumnLaravelTidyTables

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/casperw-laravel-tidy-tables/health.svg)

```
[![Health](https://phpackages.com/badges/casperw-laravel-tidy-tables/health.svg)](https://phpackages.com/packages/casperw-laravel-tidy-tables)
```

###  Alternatives

[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[rutorika/sortable

Adds sortable behavior and ordering to Laravel Eloquent models. Grouping and many to many supported.

299992.5k14](/packages/rutorika-sortable)[indexzer0/eloquent-filtering

Powerful eloquent filtering

22425.9k3](/packages/indexzer0-eloquent-filtering)[akaunting/laravel-sortable

Sortable behavior package for Laravel

27175.6k](/packages/akaunting-laravel-sortable)[phaza/single-table-inheritance

Single Table Inheritance Trait

1515.8k](/packages/phaza-single-table-inheritance)

PHPackages © 2026

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