PHPackages                             ntimyeboah/laravel-database-trigger - 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. ntimyeboah/laravel-database-trigger

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

ntimyeboah/laravel-database-trigger
===================================

A package to add database trigger to Laravel migrations

v8.5.0(1y ago)2034.5k—0%6[1 PRs](https://github.com/NtimYeboah/laravel-database-trigger/pulls)MITPHPPHP ^8.2CI passing

Since Sep 20Pushed 1y ago3 watchersCompare

[ Source](https://github.com/NtimYeboah/laravel-database-trigger)[ Packagist](https://packagist.org/packages/ntimyeboah/laravel-database-trigger)[ RSS](/packages/ntimyeboah-laravel-database-trigger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (24)Used By (0)

Add database trigger to Laravel migrations
==========================================

[](#add-database-trigger-to-laravel-migrations)

[![Total Downloads](https://camo.githubusercontent.com/4ed3ecf1ccdcce5aeee738b8a6ff83f0bb8fae0442ceac6a430b267133e0a432/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e74696d7965626f61682f6c61726176656c2d64617461626173652d747269676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ntimyeboah/laravel-database-trigger)[![Build Status](https://github.com/NtimYeboah/laravel-database-trigger/actions/workflows/tests.yml/badge.svg)](https://github.com/NtimYeboah/laravel-database-trigger/actions/workflows/tests.yml/badge.svg)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Laravel Database Trigger provides a way to add database trigger to laravel migrations just like you would with database table. A trigger is a named database object that is associated with a table, and that activates when a particular event occurs for the table. Read more about triggers [here](https://dev.mysql.com/doc/refman/8.0/en/triggers.html).

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

[](#installation)

Laravel Database Trigger requires at least [PHP](https://php.net) 8.2. This particular version supports Laravel v11.\*. Check the table below for versions support.

Package versionLaravel versionPHP version15.5, 5.6, 5.7&gt;= 7.12.\*5.8&gt;= 7.1.33.\*6.\*&gt;= 7.2.5 or &gt;= 8.04.\*7.\*&gt;= 7.2.5 or &gt;= 8.05.\*8.\*&gt;= 7.3 or &gt;= 8.06.\*9.\*&gt;=8.07.\*10.\*&gt;=8.18.\*11.\* , 12.\*&gt;=8.2This package currently supports MySQL only.

To get the latest version, simply require the package using [Composer](https://getcomposer.org):

```
composer require ntimyeboah/laravel-database-trigger
```

Once installed, if you are not using automatic package discovery, then you need to register the `NtimYeboah\LaravelDatabaseTrigger\TriggerServiceProvider` service provider in your `config/app.php`.

Usage
-----

[](#usage)

Create a trigger migration file using the `make:trigger` artisan command. The command requires the name of the trigger, name of the event object table, action timing and the event that activates the trigger.

```
php artisan make:trigger after_users_update
```

### Event object table

[](#event-object-table)

The event object table is the name of the table the trigger is associated with.

### Action timing

[](#action-timing)

The activation time for the trigger. Possible values are `after` and `before`.

`after` - Process action after the change is made on the event object table.

`before` - Process action prior to the change is made on the event object table.

### Event

[](#event)

The event to activate trigger. A trigger event can be `insert`, `update` and `delete`.

`insert` - Activate trigger when an insert operation is performed on the event object table.

`update` - Activate trigger when an update operation is performed on the event object table.

`delete` - Activate trigger when a delete operation is performed on the event object table.

The following trigger migration file will be generated for a trigger that uses `after_users_update` as a name, `users` as event object table name, `after` as action timing and `update` as event.

```
use Illuminate\Database\Migrations\Migration;
use NtimYeboah\LaravelDatabaseTrigger\TriggerFacade as Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('after_users_update')
            ->on('users')
            ->statement(function() {
                return '//...';
            })
            ->after()
            ->update();
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('after_users_update');
    }
};
```

Return the trigger statement from the closure of the `statement` method.

The following is an example trigger migration to insert into the `users_audit` table after updating a user row.

```
...

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('after_users_update')
            ->on('users')
            ->statement(function() {
                return 'insert into `users_audit` (`name`, `email`) values (old.name, old.email);';
            })
            ->after()
            ->update();
    }

...
```

Testing
-------

[](#testing)

Run the tests with:

```
$ composer test
```

Consider hiring me
------------------

[](#consider-hiring-me)

I am currently seeking new employment opportunities and would appreciate it if you'd keep me in mind for roles such as Backend Developer. Kindly contact me at:

This is a link to my CV: [Ntim Yeboah CV](https://docs.google.com/document/d/1jXVsN1NU5AH2XhStxjuwumGIqunoyk0cPPXZr6viaNs/edit?usp=sharing)

Changelog
---------

[](#changelog)

Please see [CHANGELOG](https://github.com/NtimYeboah/laravel-database-trigger/blob/master/CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/NtimYeboah/laravel-database-trigger/blob/master/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover a security vulnerability within this package, please send an e-mail to Ntim Yeboah at . All security vulnerabilities will be promptly addressed.

License
-------

[](#license)

Laravel Database Trigger is licensed under [The MIT License (MIT)](LICENSE).

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance44

Moderate activity, may be stable

Popularity37

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 95.6% 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 ~117 days

Recently: every ~6 days

Total

21

Last Release

440d ago

Major Versions

v3.0.0 → v4.x-dev2022-02-08

v4.0.0 → v5.x-dev2022-02-08

v5.0.0 → v6.x-dev2025-02-01

v6.0.0 → v7.x-dev2025-02-01

v7.0.0 → v8.x-dev2025-02-02

PHP version history (7 changes)v1.0.0PHP ^7.1

v2.x-devPHP ^7.1.3

v3.x-devPHP ^7.2.5|^8.0

v5.x-devPHP ^7.3|^8.0

v6.x-devPHP ^8.0

v7.x-devPHP ^8.1

v8.x-devPHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/d9789811ef6a364a9920860c12abf5c3ae889c20436364d008c5b5a0b454b49f?d=identicon)[NtimYeboah](/maintainers/NtimYeboah)

---

Top Contributors

[![NtimYeboah](https://avatars.githubusercontent.com/u/8011922?v=4)](https://github.com/NtimYeboah "NtimYeboah (130 commits)")[![lacasera](https://avatars.githubusercontent.com/u/8544587?v=4)](https://github.com/lacasera "lacasera (3 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")

---

Tags

databaselaravelmysqlphptriggerlaraveldatabasetriggerNtimYeboahlaravel-database-trigger

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ntimyeboah-laravel-database-trigger/health.svg)

```
[![Health](https://phpackages.com/badges/ntimyeboah-laravel-database-trigger/health.svg)](https://phpackages.com/packages/ntimyeboah-laravel-database-trigger)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

163166.8k](/packages/cybercog-laravel-clickhouse)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)

PHPackages © 2026

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