PHPackages                             simone-bianco/laravel-patches - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. simone-bianco/laravel-patches

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

simone-bianco/laravel-patches
=============================

Laravel package to manage patches for your application, like database migrations but for code.

1.0.0(10mo ago)20MITPHPPHP &gt;=8.3

Since Sep 27Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/simone-bianco/laravel-patches)[ Packagist](https://packagist.org/packages/simone-bianco/laravel-patches)[ RSS](/packages/simone-bianco-laravel-patches/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (7)Versions (7)Used By (0)

Laravel Data Patches
====================

[](#laravel-data-patches)

This package provides a migration-like system for incremental Laravel data changes. It is designed for data that should be ordered, replayable, reversible, and easier to review than a large monolithic seeder.

Use it for:

- Replacing bulky Laravel seeders with small, ordered data patches.
- Seeding initial application data such as roles, settings, content, sources, reference data, or demo/domain records.
- Deploying controlled production data changes that need a rollback path.
- Keeping large seed payloads close to their patch without making every support file executable.

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

[](#installation)

```
composer require simonebianco/laravel-patches
php artisan vendor:publish --provider="SimoneBianco\Patches\PatchesServiceProvider"
php artisan migrate
```

Publishing creates:

- `config/sb-patches.php`
- a migration for the `sb_patches` tracking table

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

[](#configuration)

`config/sb-patches.php` can define global hooks around patch execution and rollback. Each hook must be a fully qualified class with an `__invoke` method.

```
return [
    'callbacks' => [
        'up' => [
            'before' => null,
            'after' => App\Patches\Hooks\ClearCache::class,
        ],
        'down' => [
            'before' => null,
            'after' => null,
        ],
    ],
];
```

Patch formats
-------------

[](#patch-formats)

The package supports two executable patch formats under `database/patches`.

### 1. Classic file patch

[](#1-classic-file-patch)

```
database/patches/settings/site/2026_07_09_000001_add_maintenance_mode.php
```

This is best for small data changes where the full patch fits cleanly in one file.

### 2. Module patch directory

[](#2-module-patch-directory)

```
database/patches/countdowns/taiwan_invasion/2026_07_09_010020_seed_projections/
  patch.php
  data.php
  data1.php
  data2.php
  notes.md
  source-map.json
```

The runner executes only `patch.php`. Any other file inside the module directory is support material and is ignored by discovery, even if it is PHP.

Module patches are the recommended format for substantial seed data. Keep `patch.php` focused on behavior and put large arrays, JSON payloads, localized copy, source maps, or helper data next to it.

Identifiers and order
---------------------

[](#identifiers-and-order)

Patch identifiers are normalized paths relative to `database/patches`.

Classic file:

```
database/patches/settings/site/2026_07_09_000001_add_maintenance_mode.php
```

identifier:

```
settings/site/2026_07_09_000001_add_maintenance_mode
```

Module patch:

```
database/patches/settings/site/2026_07_09_000001_add_maintenance_mode/patch.php
```

identifier:

```
settings/site/2026_07_09_000001_add_maintenance_mode
```

Execution order is alphabetical/natural by identifier. This keeps ordering based on names and timestamp prefixes, regardless of whether a patch is a direct file or a module directory.

A duplicate classic/module identifier is invalid. For example, these two cannot coexist:

```
database/patches/foo/2026_07_09_000001_seed.php
database/patches/foo/2026_07_09_000001_seed/patch.php
```

Creating patches
----------------

[](#creating-patches)

Create a classic patch file:

```
php artisan make:patch settings/site/add_maintenance_mode
```

Create a module patch directory:

```
php artisan make:patch countdowns/taiwan_invasion/seed_projections --module
```

Create a module patch with an empty `data.php` file:

```
php artisan make:patch countdowns/taiwan_invasion/seed_projections --module --data
```

`--data` implies `--module`.

Patch structure
---------------

[](#patch-structure)

A patch returns an anonymous class extending `Patch`.

```
