staudenmeir/laravel-migration-views
Laravel Migration Views adds createView and dropView macros to Laravel's schema Blueprint, letting you create and drop database views directly in migrations alongside your tables. Supports MySQL, PostgreSQL, SQLite and SQL Server.
Architecture fit. The package is a thin extension of Laravel's schema builder — Schema::createView(), createOrReplaceView(), dropView(), and rename — emitted as ordinary DDL inside ordinary migration files. For a Laravel application where php artisan migrate is already the single source of truth for schema, this is the lowest-friction place a database view can live: it inherits versioning, code review, CI execution, and rollback for free. The best-fit use cases are reporting read models shared by several Eloquent models or a BI connection, denormalized export surfaces, and compatibility shims over legacy tables during a refactor. It fits poorly where a DBA or platform team owns schema changes through separate tooling, or where views logically belong to a warehouse/BI platform rather than the application database. As a TPM, treat "fit" as a governance question first and a technical one second: adopting this creates a second path to schema change unless the migration pipeline is already uncontested.
Integration feasibility. High and cheap. Composer require, auto-discovered service provider, no config to publish, one migration file to prove it out. MySQL, PostgreSQL, SQLite, and SQL Server are covered, which is the realistic production/CI matrix. v1.12 is a compatibility-only release — Laravel 13 support, no API changes, no deprecations, no breaking changes — so for a team planning a Laravel 13 upgrade this is a checklist item cleared at near-zero cost, not a feature bet. The low opportunity score (~38) is consistent with that read: the package removes friction, it does not open new product surface. Fund it as a hygiene line item, not a roadmap initiative.
Technical risk. Low for the release, moderate for the pattern. The release is a constraint bump. The pattern carries the real exposure: view dependency ordering inside the migration timeline, database permissions for CREATE/DROP VIEW in each environment, rollback correctness (an orphaned view silently shadowing a table name produces confusing failures on the next deploy, not this one), cross-engine SQL dialect divergence, and whether php artisan schema:dump / restore round-trips views faithfully. None of these are exotic, but each has a plausible production failure path, and each is cheap to test and expensive to discover.
Key questions to resolve before committing a roadmap slot.
REFRESH MATERIALIZED VIEW CONCURRENTLY. This is a material discrepancy for any dashboarding workstream: if materialized views are covered, they arrive with an unevaluated refresh lifecycle; if not, that lifecycle is a separate design with a separate owner. Resolve against the README and source before scoping.Stack fit. Introduce it where views are already part of application schema and already depended on by more than one consumer. The ceremony of a migration file is repaid the first time a report definition changes and someone has to prove what changed. Skip it for throwaway or single-consumer views.
Migration path. Inventory first: which views live in hand-written SQL, which live in deploy runbooks, which exist only in production and were never written down. Convert opportunistically — one low-risk reporting view, then the next — never as a big-bang rewrite. Establish conventions before the second migration exists, because they are far harder to retrofit than to set: one migration per view, created after the tables it selects from, with a matching down(). Changes to an existing view get a new migration; never edit an applied one. Note the PostgreSQL constraint that CREATE OR REPLACE VIEW cannot change a view's output column list — that requires drop-and-recreate plus re-granting permissions — so treat view column names as a stable public contract. Avoid select * in view bodies so base-table changes fail loudly at migration time rather than silently reshaping the view.
Compatibility. The gate is the application's Laravel/PHP constraint set plus the database engine's treatment of views, not the package API. Driver support is uneven in practice: plain views span all four engines; materialized views, if present at all, are PostgreSQL-only and will break an SQLite CI suite unless explicitly guarded. Record both facts in the compatibility matrix so nobody rediscovers them during an upgrade.
Sequencing.
Maintenance. Small footprint, single maintainer, pinned version. Include the package in every Laravel upgrade test pass and read release notes on bump. v1.12 is a routine compatibility release — a positive maintenance signal, not an operational change. The real long-term cost is not the package but the view definitions themselves, which accumulate and each need an owner. Assign ownership per view at creation time, or the reporting layer becomes tribal knowledge again with cleaner tooling.
Support. Set expectations that behavior depends on the database and on Laravel's schema builder, not on the package alone. Internal ownership must cover migration review and rollback procedure; there is no vendor to escalate to. The exit cost is genuinely low — view migrations are plain SQL and can be reimplemented with DB::statement — but write that fallback down before you need it, and note that dropping the package does not drop the views.
Scaling. Views scale with the query planner, not with this package. The scaling risk is organizational: as the view count grows, so does the dependency graph inside the migration timeline, and a single misordered or orphaned view can block the deploy path for everything behind it. Keep view migrations small, named predictably, and ordered after their dependencies; treat the migration file as the unit of review.
Failure modes to design against. Orphaned views shadowing table names after a partial rollback; missing CREATE/DROP VIEW grants in a new environment; dialect divergence between CI (often SQLite) and production (often PostgreSQL or MySQL); schema dump/restore quietly omitting a view and producing a green build against an incomplete schema; and silently widened views from select * after a base-table change. Each maps to one cheap guard: a rollback test, a permissions check in environment provisioning, a production-engine CI job for view migrations, a dump/restore round-trip assertion, and a lint rule against select *.
Ramp-up. Near zero for anyone who has written a Laravel migration — the API surface is four methods and the learning is in the conventions, not the code. Budget the onboarding cost at a short written convention note plus one example migration in-repo, and expect the first converted view to take an afternoon and the second to take an hour.
How can I help you explore Laravel packages today?