Anvil
Anvil - The mobile companion for Laravel Forge. Available now. Download for iOS

Commands

Laravel Patches provides several commands to manage your patches.

Creating Patches

make:patch

Create a new patch file:

1php artisan make:patch patch_name

This creates a timestamped patch file in database/patches.


Running Patches

patch

Run all pending patches:

1php artisan patch

Options:

  • --force - Force the operation to run in production
  • --step - Run each patch in its own batch (allows individual rollback)
  • --dry-run - Preview patches without executing them

Examples:

1# Run in production
2php artisan patch --force
3 
4# Run each patch in separate batches
5php artisan patch --step
6 
7# Preview what would run
8php artisan patch --dry-run

Dry Run Mode:

The --dry-run flag lets you safely preview which patches would execute without making any database changes:

1php artisan patch --dry-run

Output example:

1Dry run mode - No patches will be executed
2
3Would run: 2024_01_01_000000_fix_user_data
4Would run: 2024_01_02_000000_update_settings
5
6Total patches: 2

Rolling Back Patches

patch:rollback

Rollback the last batch of patches:

1php artisan patch:rollback

Options:

  • --step=X - Rollback X number of patches

Examples:

1# Rollback last batch
2php artisan patch:rollback
3 
4# Rollback last 3 patches
5php artisan patch:rollback --step=3

Viewing Patch Status

patch:status

Display comprehensive status of all patches:

1php artisan patch:status

Options:

  • --pending - Show only pending patches
  • --ran - Show only executed patches
  • --batch=N - Filter by batch number

Output Example:

1β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
2β”‚ Status β”‚ Patch β”‚ Batch β”‚ Ran On β”‚ Time (ms) β”‚ Status β”‚
3β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
4β”‚ βœ“ β”‚ 2024_01_01_fix_users β”‚ 1 β”‚ 2024-01-15 10:30:00 β”‚ 145 β”‚ Success β”‚
5β”‚ βœ“ β”‚ 2024_01_02_update_settings β”‚ 1 β”‚ 2024-01-15 10:30:01 β”‚ 89 β”‚ Success β”‚
6β”‚ β‹― β”‚ 2024_01_03_cleanup_data β”‚ Pendingβ”‚ - β”‚ - β”‚ Pending β”‚
7β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
8
9Ran: 2
10Pending: 1
11Total: 3

Examples:

1# Show only pending patches
2php artisan patch:status --pending
3 
4# Show only executed patches
5php artisan patch:status --ran
6 
7# Show patches from batch 2
8php artisan patch:status --batch=2

Listing Patches

patch:list

List all available patches with optional filtering:

1php artisan patch:list

Options:

  • --status=STATUS - Filter by status (pending, ran, failed)
  • --batch=N - Filter by batch number
  • --json - Output as JSON

Examples:

1# List all patches
2php artisan patch:list
3 
4# List only pending patches
5php artisan patch:list --status=pending
6 
7# List patches from batch 1
8php artisan patch:list --batch=1
9 
10# Output as JSON
11php artisan patch:list --json

JSON Output Example:

1[
2 {
3 "name": "2024_01_01_fix_users",
4 "status": "success",
5 "batch": 1,
6 "ran_on": "2024-01-15 10:30:00",
7 "execution_time_ms": 145
8 },
9 {
10 "name": "2024_01_02_update_settings",
11 "status": "pending",
12 "batch": null,
13 "ran_on": null,
14 "execution_time_ms": null
15 }
16]

Command Summary

Command Description
make:patch Create a new patch file
patch Run pending patches
patch:rollback Rollback patches
patch:status View patch status
patch:list List all patches

Best Practices

  1. Always use --dry-run first in production to preview changes
  2. Use --step mode when testing new patches for easier rollback
  3. Check status regularly with patch:status to monitor your patches
  4. Use descriptive names when creating patches
  5. Test patches in staging before running in production