PHPackages                             envor/laravel-schema-macros - 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. envor/laravel-schema-macros

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

envor/laravel-schema-macros
===========================

Some helpful (database level) macros for laravel's schema builder. Requires Laravel 11.

v1.1.6(1y ago)310.1k—5.6%[3 PRs](https://github.com/envor/laravel-schema-macros/pulls)4MITPHPPHP ^8.2CI passing

Since Feb 4Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/envor/laravel-schema-macros)[ Packagist](https://packagist.org/packages/envor/laravel-schema-macros)[ Docs](https://github.com/envor/laravel-schema-macros)[ GitHub Sponsors](https://github.com/envor)[ RSS](/packages/envor-laravel-schema-macros/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (16)Used By (4)

laravel-schema-macros
=====================

[](#laravel-schema-macros)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9377789e302f4f3f8da3487982eebd40c6ef4b6f90b345b22b3f1285eef2074e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e766f722f6c61726176656c2d736368656d612d6d6163726f732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/envor/laravel-schema-macros)[![GitHub Tests Action Status](https://camo.githubusercontent.com/856842c97919ed7583006ef705b54cabc72472a24df00713b3f30c149e5f76d4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656e766f722f6c61726176656c2d736368656d612d6d6163726f732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/envor/laravel-schema-macros/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/06b55d8db5d6da14349814a934912930e8c4dffa41e09a85f545037896cfdf44/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656e766f722f6c61726176656c2d736368656d612d6d6163726f732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/envor/laravel-schema-macros/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/836a922945b1c17b23d854406ecdbbf2fb4b2962d8a6a0a67863ce1fe1164f85/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e766f722f6c61726176656c2d736368656d612d6d6163726f732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/envor/laravel-schema-macros)

Some helpful (database level) macros for laravel's schema builder. Requires Laravel 11.

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

[](#installation)

You can install the package via composer:

```
composer require envor/laravel-schema-macros
```

Usage
-----

[](#usage)

[databaseExists()](#databaseexists)
[createDatabaseIfNotExists()](#createdatabaseifnotexists)
[trashDatabase()](#trashdatabase)
[emptyTrash()](#emptytrash)
[copyTable()](#copytable)

### \#`databaseExists()`

[](#databaseexists)

The `databaseExists()` method determines if the given database exists:

```
use Illuminate\Support\Facades\Schema;

$database = database_path('my-new-database.sqlite');

Schema::connection('sqlite')->databaseExists($database);

// false

touch($database);

Schema::connection('sqlite')->databaseExists($database);

// true

Schema::connection('mysql')->databaseExists('abc');

// false

Schema::connection('mysql')->createDatabase('abc');

Schema::connection('mysql')->databaseExists('abc');

// true
```

### \#`createDatabaseIfNotExists()`

[](#createdatabaseifnotexists)

The `createDatabaseIfNotExists()` method creates the given database if it does not exist:

```
use Illuminate\Support\Facades\Schema;

$default = database_path('database.sqlite');

touch($default);

Schema::connection('sqlite')->createDatabaseIfNotExists($default);

// false

Schema::connection('sqlite')->createDatabaseIfNotExists(database_path('another_database'));

// true

Schema::connection('mysql')->createDatabaseIfNotExists('brand_new_database');

// true
```

The `createDatabaseIfNotExists()` method will also create `sqlite` database files recursively:

```
$newFile = database_path('/new/directories/will/be/created/recursively/db.sqlite');

Schema::connection('sqlite')->createDatabaseIfNotExists($newFile);

// true
```

### \#`trashDatabase()`

[](#trashdatabase)

The `trashDatabase()` method will move the database to the `trash` and timestamp it:

Tip

Sqlite databases are moved to a `.trash` directory on the local storage disk by default.
You may optionally pass the name of another storage disk as a second argument.

```
$database = database_path('database.sqlite');

Schema::connection('sqlite')->trashDatabase($database);

// /home/forge/mysite.com/storage/app/.trash/2024-02-04_06-29-11_database.sqlite

Schema::connection('mariadb')->trashDatabase('schema_demo');

// trashed_2024-02-04_06-44-42_schema_demo
```

### \#`emptyTrash()`

[](#emptytrash)

The `emptyTrash()` method will erase all `trashed` databases from disk which are reachable from the current connection:

Tip

To only permanently erase databases trashed later than a given age and keep those which are newer,
you may pass the maximum age in days for the databases you want to keep.

```
$database = database_path('database.sqlite');

Schema::connection('sqlite')->trashDatabase($database);

// /home/forge/mysite.com/storage/app/.trash/2024-02-04_06-29-11_database.sqlite

Schema::connection('sqlite')->emptyTrash();

// 1

Schema::connection('mysql')->trashDatabase('schema_demo');

// trashed_2024-02-04_06-44-42_schema_demo

Schema::connection('mysql')->emptyTrash();

// 1
```

### \#`copyTable()`

[](#copytable)

The `copyTable()` method will copy the given table:

```
$database = database_path('database.sqlite');

Schema::connection('sqlite')->copyTable('users');

// users_copy

Schema::connection('sqlite')->copyTable('users', 'users_snapshot_1');

// users_snapshot_1
```

Testing
-------

[](#testing)

Important

Tests use [spatie/docker](https://github.com/spatie/docker) for testing against various database servers.
Docker is required for running tests locally!

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [inmanturbo](https://github.com/envor)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance64

Regular maintenance activity

Popularity27

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 79.3% 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 ~16 days

Recently: every ~41 days

Total

12

Last Release

657d ago

Major Versions

v0.0.1 → v1.0.02024-02-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/0261babef618b8fb3bfcea84376ed5e71e7169586eb8de63a6550c2e7ea653a6?d=identicon)[inmanturbo](/maintainers/inmanturbo)

---

Top Contributors

[![inmanturbo](https://avatars.githubusercontent.com/u/47095624?v=4)](https://github.com/inmanturbo "inmanturbo (69 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

laravelmysqlsqlitelaravelenvorlaravel-schema-macros

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/envor-laravel-schema-macros/health.svg)

```
[![Health](https://phpackages.com/badges/envor-laravel-schema-macros/health.svg)](https://phpackages.com/packages/envor-laravel-schema-macros)
```

###  Alternatives

[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

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

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[spatie/laravel-deleted-models

Automatically copy deleted records to a separate table

409109.8k4](/packages/spatie-laravel-deleted-models)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

203330.1k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

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