PHPackages                             gboquizosanchez/hew - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. gboquizosanchez/hew

ActiveLibrary[Testing &amp; Quality](/categories/testing)

gboquizosanchez/hew
===================

Schema as source of truth for Laravel migrations

1.0.0(today)00PHPPHP ^8.1

Since Jun 19Pushed todayCompare

[ Source](https://github.com/gboquizosanchez/hew)[ Packagist](https://packagist.org/packages/gboquizosanchez/hew)[ RSS](/packages/gboquizosanchez-hew/feed)WikiDiscussions main Synced today

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

[![hew](https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/2692.svg)](https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/2692.svg)`gboquizosanchez/hew`
=====================

[](#gboquizosanchezhew)

**Schema as source of truth for Laravel migrations**

[![Latest Stable Version](https://camo.githubusercontent.com/1ab5f3ef23515bb2b43ee58b8db2d2938f3cef02c3fe290662c1eff2dd7a9728/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67626f7175697a6f73616e6368657a2f6865772e737667)](https://packagist.org/packages/gboquizosanchez/hew)[![Total Downloads](https://camo.githubusercontent.com/a72821e4381096da691368b4f19dc4f94183175af0f01796e36621ad1493bf30/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f67626f7175697a6f73616e6368657a2f6865772e737667)](https://packagist.org/packages/gboquizosanchez/hew)[![PHP](https://camo.githubusercontent.com/412440dde67ba53be401aa8440d704b5f973cea2cd63759440a0a142bd34fd3b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e312d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/gboquizosanchez/hew)[![Laravel](https://camo.githubusercontent.com/5ed5d963280b1293ea5c652a3c7d787f7d60559610113a3acb4e09ad848ccfef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302532302537432532303131253230253743253230313225323025374325323031332d4646324432303f6c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/gboquizosanchez/hew)[![License: MIT](https://camo.githubusercontent.com/6fd529fdc57adf8eb89582bee619d571fd9037b380418c50bb57e9c91598e03b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d3232433535452e737667)](LICENSE.md)[![PHPStan](https://camo.githubusercontent.com/f9b288f4093bcfed63270d4f62142fdfa9f78198a14be806f77f722e9103fcf6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c25323031302d626c7565)](https://phpstan.org/)[![Tests](https://camo.githubusercontent.com/600447d23e0f73abc4988a83007993cf06dbbac7db0af553fd0a9c63d65a0b8f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54657374732d5065737425323076342d394332374230)](https://pestphp.com/)

---

*Where is the `avatar` column defined? In migration number 47.**hew makes that a one-line answer.*

---

Why hew?
--------

[](#why-hew)

Laravel migrations are append-only by design — great for versioning, painful for understanding the current state.

ProblemWithout hewWith hew"Does `users` have an `avatar` column?"❌ Read through N migrations✅ One glance at `schema.php`Adding a column to an existing table❌ Write migration by hand✅ Add it to the schema, run `hew:sync`Reviewing the full database structure❌ Mental model from git history✅ Single file, fluent APICI check for uncommitted schema drift❌ No built-in mechanism✅ `hew:diff` exits `1` when changes pendingAccidental destructive migration❌ Easy to do✅ Impossible — hew never emits `DROP`---

🚀 Features
----------

[](#-features)

- **Single source of truth**: `database/schema.php` is the canonical description of your database.
- **Additive-only**: hew never emits `DROP COLUMN`, `RENAME COLUMN`, or `DROP TABLE`. Removed columns produce warnings, not data loss.
- **Fluent column API**: Chainable modifiers — `->nullable()`, `->unique()`, `->default()`, `->references()` and more.
- **Relation metadata**: Declare `hasMany`, `belongsTo`, `belongsToMany` directly on the table definition. `belongsToMany` auto-generates the pivot table.
- **Import from existing migrations**: `hew:import` generates `schema.php` from an existing migration history — zero manual work to adopt hew on a live project.
- **CI-friendly**: `hew:diff` exits `1` when changes are pending, making it trivially embeddable in pipelines.
- **Zero runtime footprint**: `--dev` only. No production dependency.

---

📦 Installation
--------------

[](#-installation)

```
composer require --dev gboquizosanchez/hew
```

Register the service provider manually. In **Laravel 11+**, add it to `bootstrap/providers.php`:

```
return [
    // ...
    \Boquizo\Hew\HewServiceProvider::class,
];
```

In **Laravel 10**, add it to the `providers` array in `config/app.php`:

```
'providers' => [
    // ...
    \Boquizo\Hew\HewServiceProvider::class,
],
```

**New project** — create `database/schema.php` from scratch (see [Define your schema](#define-your-schema) below).

**Existing project** — generate `schema.php` from your migrations with:

```
php artisan hew:import
```

---

🔧 Usage
-------

[](#-usage)

### Define your schema

[](#define-your-schema)

```
