Download the PHP package mattkingshott/triggers without Composer
On this page you can find all versions of the php package mattkingshott/triggers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mattkingshott/triggers
More information about mattkingshott/triggers
Files in mattkingshott/triggers
Package triggers
Short Description A package to add database trigger support to Laravel
License MIT
Homepage https://github.com/mattkingshott/triggers
Informations about the package 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
Pull in the package using Composer:
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
To create a trigger, simply call the table
method on the Triggers\Trigger
class:
Key
By default, the class will generate a name for the trigger using the following convention:
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:
When a key is specified, the trigger name is derived from the following convention:
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:
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.
Example
The following example shows a migration that creates a posts
table and then assigns the trigger to it.
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
The MIT License (MIT). Please see License File for more information.