PHPackages                             staudenmeir/laravel-migration-views - 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. staudenmeir/laravel-migration-views

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

staudenmeir/laravel-migration-views
===================================

Laravel database migrations with SQL views

v1.12(2mo ago)2161.7M↓36%186MITPHPPHP ^8.2CI passing

Since Jun 15Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/staudenmeir/laravel-migration-views)[ Packagist](https://packagist.org/packages/staudenmeir/laravel-migration-views)[ Fund](https://paypal.me/JonasStaudenmeir)[ RSS](/packages/staudenmeir-laravel-migration-views/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (30)Used By (6)

Laravel Migration Views
=======================

[](#laravel-migration-views)

[![CI](https://github.com/staudenmeir/laravel-migration-views/actions/workflows/ci.yml/badge.svg)](https://github.com/staudenmeir/laravel-migration-views/actions/workflows/ci.yml?query=branch%3Amain)[![Code Coverage](https://camo.githubusercontent.com/f077efd761489f1e70fbb018660658b83dc836d6407ec91f1a1e1b05f12650f0/68747470733a2f2f636f6465636f762e696f2f67682f7374617564656e6d6569722f6c61726176656c2d6d6967726174696f6e2d76696577732f67726170682f62616467652e7376673f746f6b656e3d375944325352544c3634)](https://codecov.io/gh/staudenmeir/laravel-migration-views)[![PHPStan](https://camo.githubusercontent.com/2b1732baa25914ee5ccbeaf42980d671de29700b49e0639e1edc8e66181f6905/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c25323031302d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/staudenmeir/laravel-migration-views/actions/workflows/static-analysis.yml?query=branch%3Amain)[![Latest Stable Version](https://camo.githubusercontent.com/29271034cd9d34deb53df52e717f96f53ac061c57c40761f92527dcd5ac54c51/68747470733a2f2f706f7365722e707567782e6f72672f7374617564656e6d6569722f6c61726176656c2d6d6967726174696f6e2d76696577732f762f737461626c65)](https://packagist.org/packages/staudenmeir/laravel-migration-views)[![Total Downloads](https://camo.githubusercontent.com/3c56985b18e8b6bc79ea534ca9bd03bf54ad0f124616f1f0f3ac06256e91131c/68747470733a2f2f706f7365722e707567782e6f72672f7374617564656e6d6569722f6c61726176656c2d6d6967726174696f6e2d76696577732f646f776e6c6f616473)](https://packagist.org/packages/staudenmeir/laravel-migration-views/stats)[![License](https://camo.githubusercontent.com/8b1e7a0550fd88b61048df538bb8532eff93ad110fa7c8c7a9b7a253f63b010c/68747470733a2f2f706f7365722e707567782e6f72672f7374617564656e6d6569722f6c61726176656c2d6d6967726174696f6e2d76696577732f6c6963656e7365)](https://github.com/staudenmeir/laravel-migration-views/blob/main/LICENSE)

This Laravel extension adds support for SQL views in database migrations.

Supports Laravel 5.5+.

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

[](#installation)

```
composer require staudenmeir/laravel-migration-views:"^1.0"

```

Use this command if you are in PowerShell on Windows (e.g. in VS Code):

```
composer require staudenmeir/laravel-migration-views:"^^^^1.0"

```

Versions
--------

[](#versions)

LaravelPackage13.x1.1212.x1.1111.x1.910.x1.79.x1.68.x1.57.x1.46.x1.25.81.15.5–5.71.0Usage
-----

[](#usage)

- [Creating Views](#creating-views)
- [Renaming Views](#renaming-views)
- [Dropping Views](#dropping-views)
- [Checking For View Existence](#checking-for-view-existence)
- [Listing View Columns](#listing-view-columns)
- [Materialized Views](#materialized-views)

### Creating Views

[](#creating-views)

Use `createView()` to create a view and provide a query builder instance or an SQL string:

```
use Staudenmeir\LaravelMigrationViews\Facades\Schema;

$query = DB::table('users')->where('active', true);

Schema::createView('active_users', $query);
```

You can provide the view's columns as the third argument:

```
use Staudenmeir\LaravelMigrationViews\Facades\Schema;

$query = 'select id from users where active = 1';

Schema::createView('active_users', $query, ['key']);
```

Use `createOrReplaceView()` to create a view or replace the existing one:

```
use Staudenmeir\LaravelMigrationViews\Facades\Schema;

$query = DB::table('users')->where('active', true);

Schema::createOrReplaceView('active_users', $query);
```

#### View Processing Algorithm

[](#view-processing-algorithm)

On MySQL and MariaDB, you can specify the view processing algorithm:

```
use Staudenmeir\LaravelMigrationViews\Facades\Schema;

$query = DB::table('users')->where('active', true);

Schema::createView('active_users', $query, algorithm: 'TEMPTABLE');
```

### Renaming Views

[](#renaming-views)

Use `renameView()` to rename a view:

```
use Staudenmeir\LaravelMigrationViews\Facades\Schema;

Schema::renameView('active_users', 'users_active');
```

### Dropping Views

[](#dropping-views)

Use `dropView()` or `dropViewIfExists()` to drop a view:

```
use Staudenmeir\LaravelMigrationViews\Facades\Schema;

Schema::dropView('active_users');

Schema::dropViewIfExists('active_users');
```

If you are using `php artisan migrate:fresh`, you can drop all views with `--drop-views` (Laravel 5.6.26+).

### Checking For View Existence

[](#checking-for-view-existence)

Use `hasView()` to check whether a view exists:

```
use Staudenmeir\LaravelMigrationViews\Facades\Schema;

if (Schema::hasView('active_users')) {
    //
}
```

### Listing View Columns

[](#listing-view-columns)

Use `getViewColumnListing()` to get the column listing for a view:

```
use Staudenmeir\LaravelMigrationViews\Facades\Schema;

$columns = Schema::getViewColumnListing('active_users');
```

### Materialized Views

[](#materialized-views)

On PostgreSQL, you can create a materialized view with `createMaterializedView()`:

```
use Staudenmeir\LaravelMigrationViews\Facades\Schema;

$query = DB::table('users')->where('active', true);

Schema::createMaterializedView('active_users', $query);
```

Use `refreshMaterializedView()` to refresh a materialized view:

```
Schema::refreshMaterializedView('active_users');
```

Use `dropMaterializedView()` or `dropMaterializedViewIfExists()` to drop a materialized view:

```
Schema::dropMaterializedView('active_users');
Schema::dropMaterializedViewIfExists('active_users');
```

Use `hasMaterializedView()` to check whether a materialized view exists:

```
if (Schema::hasMaterializedView('active_users')) {
    //
}
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) and [CODE OF CONDUCT](.github/CODE_OF_CONDUCT.md) for details.

###  Health Score

67

—

FairBetter than 100% of packages

Maintenance85

Actively maintained with recent releases

Popularity58

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 98.9% 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 ~98 days

Recently: every ~61 days

Total

26

Last Release

78d ago

Major Versions

v1.12 → 8.5.x-dev2026-03-01

PHP version history (10 changes)v1.0PHP &gt;=7.0

v1.1PHP ^7.1.3

v1.2PHP ^7.2

v1.4PHP ^7.2.5

v1.5PHP ^7.3

v1.5.1PHP ^7.3|^8.0

v1.6PHP ^8.0.2

v1.7PHP ^8.1

v1.9PHP ^8.2

8.5.x-devPHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c1c3cda28d147c1899037c3187f89a606ca14f51190de59e88fa91e51647ff6?d=identicon)[staudenmeir](/maintainers/staudenmeir)

---

Top Contributors

[![staudenmeir](https://avatars.githubusercontent.com/u/1853169?v=4)](https://github.com/staudenmeir "staudenmeir (88 commits)")[![lonnylot](https://avatars.githubusercontent.com/u/656791?v=4)](https://github.com/lonnylot "lonnylot (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/staudenmeir-laravel-migration-views/health.svg)

```
[![Health](https://phpackages.com/badges/staudenmeir-laravel-migration-views/health.svg)](https://phpackages.com/packages/staudenmeir-laravel-migration-views)
```

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[staudenmeir/eloquent-json-relations

Laravel Eloquent relationships with JSON keys

1.1k5.8M24](/packages/staudenmeir-eloquent-json-relations)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[gearbox-solutions/eloquent-filemaker

A package for getting FileMaker records as Eloquent models in Laravel

6454.8k2](/packages/gearbox-solutions-eloquent-filemaker)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)

PHPackages © 2026

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