π Enjoying this package? Consider sponsoring me on GitHub or buying me a beer.
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 production2php artisan patch --force3 4# Run each patch in separate batches5php artisan patch --step6 7# Preview what would run8php 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 executed23Would run: 2024_01_01_000000_fix_user_data4Would run: 2024_01_02_000000_update_settings56Total 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 batch2php artisan patch:rollback3 4# Rollback last 3 patches5php 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: 210Pending: 111Total: 3
Examples:
1# Show only pending patches2php artisan patch:status --pending3 4# Show only executed patches5php artisan patch:status --ran6 7# Show patches from batch 28php 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 JSON11php 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": null15 }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
- Always use
--dry-runfirst in production to preview changes - Use
--stepmode when testing new patches for easier rollback - Check status regularly with
patch:statusto monitor your patches - Use descriptive names when creating patches
- Test patches in staging before running in production