PHPackages                             mattkingshott/triggers - 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. mattkingshott/triggers

Abandoned → [caneara/triggers](/?search=caneara%2Ftriggers)ArchivedLibrary[Database &amp; ORM](/categories/database)

mattkingshott/triggers
======================

A package to add database trigger support to Laravel

v1.0.1(3y ago)345.6k12MITPHPPHP ^8.0

Since Feb 6Pushed 3y ago2 watchersCompare

[ Source](https://github.com/caneara/triggers)[ Packagist](https://packagist.org/packages/mattkingshott/triggers)[ Docs](https://github.com/mattkingshott/triggers)[ RSS](/packages/mattkingshott-triggers/feed)WikiDiscussions main Synced 1mo ago

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

Triggers
========

[](#triggers)

This package enables the use of database triggers within Laravel applications. Note that your chosen database must support triggers for the package to work.

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

[](#installation)

Pull in the package using Composer:

```
composer require caneara/triggers
```

Usage
-----

[](#usage)

Triggers can only be added to existing tables. Therefore, when creating triggers in your migration files, make sure you add them after the `Schema::create` method.

### Table

[](#table)

To create a trigger, simply call the `table` method on the `Triggers\Trigger` class:

```
use Triggers\Trigger;

Trigger::table('posts');
```

### Key

[](#key)

By default, the class will generate a name for the trigger using the following convention:

```
trigger_{TABLE}_{TIME}_{EVENT}

```

However, since trigger names must be unique across the database, if you were to create two triggers that used the same event and time (these concepts are covered in the next section), then you'd get an error.

To address this problem, the class offers a `key` method that allows you to add your own custom text to the trigger's name, thereby ensuring that the trigger name can be made unique:

```
Trigger::table('posts')->key('custom');
```

When a key is specified, the trigger name is derived from the following convention:

```
trigger_{TABLE}_{KEY}_{TIME}_{EVENT}

```

### Event and time

[](#event-and-time)

Next, you need to specify whether the trigger should be fired for an `INSERT`, `UPDATE` or `DELETE` event. You will also need to specify whether the trigger should run `BEFORE` or `AFTER` the event has taken place:

```
Trigger::table('posts')->beforeDelete();
Trigger::table('posts')->beforeInsert();
Trigger::table('posts')->beforeUpdate();

Trigger::table('posts')->afterDelete();
Trigger::table('posts')->afterInsert();
Trigger::table('posts')->afterUpdate();
```

### Statement

[](#statement)

The final step, is to specify the SQL statement(s) that should be executed by the trigger when it is fired. To do this, supply a `Closure` to the event / time method. Note that the `Closure` must return a SQL `string` e.g.

```
Trigger::table('posts')->afterInsert(function() {
    return "UPDATE `users` SET `posts` = 1 WHERE `id` = NEW.user_id;";
});
```

### Example

[](#example)

The following example shows a migration that creates a `posts` table and then assigns the trigger to it.

```
use Triggers\Trigger;

class CreatePostsTable extends Migration
{
    public function up() : void
    {
        Schema::create('posts', function(Blueprint $table) {
            $table->unsignedTinyInteger('id');
            $table->string('title');
        });

        Trigger::table('posts')->key('count')->afterInsert(function() {
            return "UPDATE `users` SET `posts` = 1 WHERE `id` = NEW.user_id;";
        });
    }
}
```

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

[](#contributing)

Thank you for considering a contribution to the project. You are welcome to submit a PR containing improvements, however if they are substantial in nature, please also be sure to include a test or tests.

License
-------

[](#license)

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

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity55

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

Every ~225 days

Total

2

Last Release

1329d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/22bc3f376c7511f4fc85e2c240cf52c075c491426795c71409c0a4b551a8bf85?d=identicon)[mattkingshott](/maintainers/mattkingshott)

---

Top Contributors

[![mattkingshott](https://avatars.githubusercontent.com/u/51963402?v=4)](https://github.com/mattkingshott "mattkingshott (17 commits)")

---

Tags

phplaraveldatabasetriggers

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mattkingshott-triggers/health.svg)

```
[![Health](https://phpackages.com/badges/mattkingshott-triggers/health.svg)](https://phpackages.com/packages/mattkingshott-triggers)
```

###  Alternatives

[renoki-co/l1

Laravel integration for Cloudflare Workers services.

16113.1k](/packages/renoki-co-l1)[calebdw/laravel-sql-entities

Manage SQL entities in Laravel with ease.

301.3k](/packages/calebdw-laravel-sql-entities)[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3516.7k3](/packages/wayofdev-laravel-cycle-orm-adapter)[tomatophp/filament-locations

Database Seeds for Countries / Cities / Areas / Languages / Currancy with ready to use resources for FilamentPHP

2320.8k6](/packages/tomatophp-filament-locations)

PHPackages © 2026

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