Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phinx Laravel Package

robmorgan/phinx

Phinx is a PHP database migration tool that lets you manage schema changes with versioned migrations and seeders. Run migrations from the CLI, track environments, and support multiple database adapters—framework-agnostic and easy to integrate into any project.

View on GitHub
Deep Wiki
Context7

PHP Database Migrations for Everyone

Frequently asked questions about Phinx
Can I use Phinx for PostgreSQL enums in Laravel without breaking Eloquent?
Yes, Phinx’s nativeenum feature works alongside Laravel’s Attribute casting. Use Phinx for schema-level enums (e.g., `nativeenum('status', ['active', 'inactive'])`) and Laravel’s `$casts` for model validation. This ensures type safety at both the database and application layers. For large tables, combine with `ALTER TABLE` strategies like temporary tables to avoid downtime.
How do I install Phinx in a Laravel project?
Run `composer require robmorgan/phinx` to install, then generate a `phinx.yml` config file with `php vendor/bin/phinx init`. Configure database connections to match your Laravel `.env` settings (e.g., `dbname: {{ env('DB_DATABASE') }}`). Phinx integrates with Laravel’s Artisan CLI, so you can use `php artisan` commands alongside `phinx migrate`.
Does Phinx support MariaDB 12’s default numeric foreign keys?
Yes, Phinx 0.16.12+ includes a fix for MariaDB 12’s numeric foreign key behavior. No action is required—existing migrations continue working. For string-based foreign keys (e.g., UUIDs), explicitly define the column type in your migration (e.g., `$table->addColumn('user_id', 'char(36)')`) to avoid conflicts.
Is Phinx compatible with Laravel’s database seeding?
Phinx supports seeders natively, which can coexist with Laravel’s Eloquent factories. Use Phinx seeders for one-time data setup (e.g., `phinx seed:run`) and Laravel’s `DatabaseSeeder` for dynamic data generation. For consistency, define seeders in `db/seeds/` and reference them in `phinx.yml` under the `seeds` section.
What Laravel versions does Phinx work with?
Phinx is framework-agnostic but works seamlessly with Laravel 8+ (PHP 8.1+). For older Laravel versions (7.x), use Phinx 0.13.x. Ensure your `phinx.yml` database config aligns with Laravel’s `.env` variables (e.g., `host: {{ env('DB_HOST') }}`). Test migrations with `phinx migrate --dry-run` before deploying to Laravel environments.
How do I handle SQL injection risks in dynamic database environments?
Phinx 0.16.12+ automatically quotes database names in `hasDatabase()` adapters, mitigating SQL injection risks. For custom adapters or legacy code, audit `phinx.yml` for hardcoded database names and update to the latest Phinx version. In Laravel, pair Phinx with `env()`-driven database configs (e.g., `config/database.php`) for secure dynamic database selection.
Can I use Phinx alongside Laravel’s Schema Builder?
Yes, but avoid redundancy. Use Phinx for cross-environment migrations (e.g., shared hosting, CI/CD) and Laravel’s Schema Builder for framework-specific logic (e.g., `Schema::create('users', ...)`). For consistency, define migrations in `database/migrations/` and run them via `phinx migrate` or `php artisan migrate`. Phinx’s CLI tools complement Laravel’s Artisan workflow.
What are the alternatives to Phinx for Laravel migrations?
Laravel’s built-in `Schema` migrations and `artisan migrate` are the primary alternatives, but Phinx offers framework-agnostic benefits like multi-database support and PostgreSQL enums. For teams using CakePHP or non-Laravel PHP, Phinx is the standard. If you need tight Laravel integration, stick to Eloquent migrations, but Phinx excels for complex schemas or multi-framework projects.
How do I test Phinx migrations in a Laravel CI pipeline?
Use `phinx migrate --dry-run` in your CI script to validate migrations without applying them. For database-agnostic testing, configure `phinx.yml` to use SQLite in CI (e.g., `adapter: sqlite`) and run migrations against a temporary database. Pair with Pest or PHPUnit to assert schema changes (e.g., `assertDatabaseHasSchema('users', ['status' => 'nativeenum'])`).
What’s the best way to manage enums in production with Phinx and Laravel?
Standardize on Phinx for schema-level enums (e.g., `nativeenum`) and Laravel for model validation (e.g., `$casts`). For zero-downtime changes, use batch migrations with `ALTER TABLE` and backup old values. In PostgreSQL, leverage `CHECK` constraints as a fallback. Document enum values in a shared config file (e.g., `config/enums.php`) to sync Phinx and Laravel logic.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/entity-migrator
codraw/doctrine-extra
codraw/aws-tool-kit
codraw/validator
codraw/workflow
codraw/open-api
codraw/cron-job
codraw/process
codraw/log
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony