PHPackages                             laratusk/view-migrations - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. laratusk/view-migrations

ActiveLibrary[Database &amp; ORM](/categories/database)

laratusk/view-migrations
========================

Manage database views via SQL files with automatic content-hash-based change detection

v0.2.0(1mo ago)031↓100%MITPHPPHP ^8.2CI failing

Since Mar 15Pushed 1mo agoCompare

[ Source](https://github.com/laratusk/view-migrations)[ Packagist](https://packagist.org/packages/laratusk/view-migrations)[ RSS](/packages/laratusk-view-migrations/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (3)Used By (0)

View Migrations for Laravel
===========================

[](#view-migrations-for-laravel)

Manage database views via plain SQL files with automatic change detection. The package computes a content hash for each view file and tracks it in Laravel's migrations table.

Supports **MySQL**, **PostgreSQL**, and **SQLite**.

Installation
------------

[](#installation)

```
composer require laratusk/view-migrations
```

Publish the config file:

```
php artisan vendor:publish --tag=view-migrations-config
```

How It Works
------------

[](#how-it-works)

1. You write plain SQL `SELECT` statements in `database/views/*.sql`
2. The package computes a content hash for each file
3. On `view:migrate`, it compares the file hash with the hash stored in the migrations table
4. Views are created, updated, or skipped accordingly

The hash is stored in Laravel's `migrations` table as `vm:{view_name}:{hash}`, keeping the tracking mechanism consistent across all database drivers.

Quick Start
-----------

[](#quick-start)

Create a view file:

```
php artisan view:make user_stats
```

Edit `database/views/user_stats.sql`:

```
SELECT
    user_id,
    COUNT(*) as total_orders,
    SUM(amount) as total_spent
FROM orders
GROUP BY user_id;
```

Apply it:

```
php artisan view:migrate
```

Commands
--------

[](#commands)

### `view:migrate`

[](#viewmigrate)

Syncs all SQL files to database views.

```
php artisan view:migrate
php artisan view:migrate --dry-run          # Preview changes without executing
php artisan view:migrate --drop-orphans     # Drop views with no matching SQL file
```

### `view:status`

[](#viewstatus)

Shows the current state of all views.

```
php artisan view:status
```

```
+-------------+--------------+--------------+--------+
| View        | File Hash    | DB Hash      | Status |
+-------------+--------------+--------------+--------+
| user_stats  | a1b2c3d4e5f6 | 9f8e7d6c5b4a | Stale  |
| daily_sales | c3d4e5f6a1b2 | c3d4e5f6a1b2 | OK     |
| new_report  | e5f6a1b2c3d4 | —            | New    |
| old_view    | —            | 7d6c5b4a9f8e | Orphan |
+-------------+--------------+--------------+--------+

```

### `view:make {name}`

[](#viewmake-name)

Creates a new SQL file in `database/views/`.

```
php artisan view:make analytics_summary
```

Usage in Migrations
-------------------

[](#usage-in-migrations)

You can trigger view migrations from Laravel migrations:

```
use Laratusk\ViewMigrations\Facades\ViewMigrator;

return new class extends Migration
{
    public function up(): void
    {
        ViewMigrator::migrateView('analytics_summary');
    }

    public function down(): void
    {
        ViewMigrator::dropView('analytics_summary');
    }
};
```

Configuration
-------------

[](#configuration)

```
// config/view-migrations.php

return [
    // Directory where .sql view files are stored
    'path' => database_path('views'),

    // Only manage views matching this prefix (null = manage all)
    'prefix' => null,
];
```

Events
------

[](#events)

EventProperties`ViewCreated``viewName`, `hash``ViewUpdated``viewName`, `oldHash`, `newHash``ViewDropped``viewName``ViewMigrationCompleted``result` (ViewMigrationResult DTO)Testing
-------

[](#testing)

```
# SQLite (default)
vendor/bin/pest

# MySQL
DB_CONNECTION=mysql DB_DATABASE=testing DB_USERNAME=root DB_PASSWORD=secret vendor/bin/pest

# PostgreSQL
DB_CONNECTION=pgsql DB_DATABASE=testing DB_USERNAME=postgres DB_PASSWORD=secret vendor/bin/pest
```

License
-------

[](#license)

MIT License. See [LICENSE.md](LICENSE.md).

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance95

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

53d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/755245aa5e4ba6c690b039cedcce5a86cd01b4f00d490cd71f03e6377ac302d5?d=identicon)[laratusk](/maintainers/laratusk)

---

Top Contributors

[![azer1ghost](https://avatars.githubusercontent.com/u/27803185?v=4)](https://github.com/azer1ghost "azer1ghost (3 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/laratusk-view-migrations/health.svg)

```
[![Health](https://phpackages.com/badges/laratusk-view-migrations/health.svg)](https://phpackages.com/packages/laratusk-view-migrations)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[watson/validating

Eloquent model validating trait.

9723.3M46](/packages/watson-validating)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
