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

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

robinhoo1973/laravel-database-trigger-5.8
=========================================

A package to add database trigger to laravel migrations

1.0(7y ago)085MITPHPPHP ^7.1

Since Mar 25Pushed 7y ago1 watchersCompare

[ Source](https://github.com/robinhoo1973/laravel-database-trigger)[ Packagist](https://packagist.org/packages/robinhoo1973/laravel-database-trigger-5.8)[ RSS](/packages/robinhoo1973-laravel-database-trigger-58/feed)WikiDiscussions master Synced today

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

Add database trigger to laravel migrations
==========================================

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

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/a6221db10e90a619603f9c319b56c4434bdec1193f8909a472a6724e5b03575f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4e74696d5965626f61682f6c61726176656c2d64617461626173652d747269676765722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/NtimYeboah/laravel-database-trigger)[![StyleCI](https://camo.githubusercontent.com/47ab2684185e545ba853f8c663fcb455e3fbea811437c4271ef3137099ead3c9/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f373534383938362f736869656c64)](https://styleci.io/repos/7548986)

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) 7.1. This particular version supports laravel at least v5.5. The 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 `TopviewDigital\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 TopviewDigital\LaravelDatabaseTrigger\TriggerFacade as Schema;

class CreateAfterUsersUpdateTrigger 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('users.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
```

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

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

2604d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0694c9e94177dbc71edcdceacc627d1cb772220e6b098f0929db8fc89814381c?d=identicon)[robinhoo1973](/maintainers/robinhoo1973)

---

Top Contributors

[![robinhoo1973](https://avatars.githubusercontent.com/u/6511003?v=4)](https://github.com/robinhoo1973 "robinhoo1973 (1 commits)")

---

Tags

databasetriggerNtimYeboahlaravel-database-trigger

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[frozennode/administrator

A database interface package for Laravel

1.9k249.4k](/packages/frozennode-administrator)[ntimyeboah/laravel-database-trigger

A package to add database trigger to Laravel migrations

2034.5k](/packages/ntimyeboah-laravel-database-trigger)[betterapp/laravel-db-encrypter

Provides database model attribute encryption/decryption

365614.7k8](/packages/betterapp-laravel-db-encrypter)[tpetry/laravel-query-expressions

Database-independent Query Expressions as a replacement to DB::raw calls

357436.5k2](/packages/tpetry-laravel-query-expressions)[summerblue/administrator

A database interface package for Laravel, modified!

29329.8k1](/packages/summerblue-administrator)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)

PHPackages © 2026

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