PHP code example of mattkingshott / triggers

1. Go to this page and download the library: Download mattkingshott/triggers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mattkingshott / triggers example snippets


use Triggers\Trigger;

Trigger::table('posts');

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

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

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

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

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;";
        });
    }
}