- How do I create a patch for a Laravel data migration that shouldn’t run automatically?
- Use `php artisan make:patch PatchName` to generate a new patch file. Write your logic in the `handle()` method of the generated command class. Patches are executed manually via `php artisan patch:run PatchName`, ensuring they only run when you trigger them.
- Does Laravel Patches work with Laravel 10, or do I need to downgrade?
- The package is officially tested with Laravel 10.x and requires PHP 8.1+. While backward compatibility with Laravel 9.x is likely, it hasn’t been explicitly tested. Always check the [GitHub repo](https://github.com/jonaaix/laravel-patches) for the latest version notes before installing.
- Can I use Laravel Patches for deployment scripts like zero-downtime database updates?
- Yes, patches are ideal for deployment tasks. Since they’re manual and trackable, you can run them as part of your deployment pipeline (e.g., via Envoyer or GitHub Actions). Just ensure your patch logic handles edge cases like partial failures, as patches run outside Laravel’s default transaction scope.
- How do I prevent a patch from running multiple times accidentally?
- Laravel Patches automatically tracks executed patches in the database via a `patches` table. Once a patch runs, it’s marked as executed and won’t run again unless you manually reset its status or delete the record. This prevents duplicates without requiring custom logic.
- What’s the difference between Laravel Patches and database migrations for one-off fixes?
- Migrations are for schema changes and run automatically during deployments, while patches are manual, disposable commands for data fixes or deployment tasks. Patches give you full control—run them when needed, delete them afterward, and avoid cluttering your codebase with obsolete scripts.
- Can I test Laravel Patches in a CI/CD pipeline before production?
- Yes, patches can be tested in isolation by running them against a staging database or test environment. Use Laravel’s testing tools to mock dependencies or simulate patch logic. Since patches are commands, you can also test them via `php artisan patch:run PatchName` in your CI workflow.
- How do I clean up old patches after they’re no longer needed?
- Simply delete the patch file from your `app/Console/Patches` directory. The package doesn’t retain patch files after execution—only the execution log in the database. To remove the log entry, use `php artisan patch:delete PatchName` or manually delete the record from the `patches` table.
- Will Laravel Patches conflict with existing migration strategies or Doctrine Migrations?
- No, patches are designed to complement—not replace—migrations. Use migrations for schema changes and patches for one-off data fixes or deployment tasks. Avoid mixing patching libraries to prevent conflicts, but Laravel Patches has no hard dependencies beyond Laravel core.
- Can I integrate Laravel Patches with Laravel Forge or Envoyer for automated deployments?
- Absolutely. Since patches are Artisan commands, you can trigger them via Forge/Envoyer deployment scripts. For example, add a post-deploy hook to run specific patches only in production. Just ensure your patch logic includes environment checks (e.g., `if (app()->environment('production'))`).
- What happens if a patch fails mid-execution? Can I roll it back?
- Patches run outside Laravel’s default transaction scope, so partial failures won’t auto-rollback. Handle errors explicitly in your patch’s `handle()` method (e.g., throw exceptions or log failures). For critical patches, consider wrapping logic in a transaction or implementing manual rollback steps.