PHP code example of esign / laravel-database-trigger
1. Go to this page and download the library: Download esign/laravel-database-trigger 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/ */
esign / laravel-database-trigger example snippets
use Esign\DatabaseTrigger\DatabaseTrigger;
use Esign\DatabaseTrigger\Enums\TriggerEvent;
use Esign\DatabaseTrigger\Enums\TriggerTiming;
use Esign\DatabaseTrigger\Facades\Schema;
Schema::createTrigger('my_trigger', function (DatabaseTrigger $trigger) {
$trigger->on('posts');
$trigger->event(TriggerEvent::INSERT);
$trigger->timing(TriggerTiming::BEFORE);
$trigger->statement("SET NEW.title = 'Default title';");
});
use Esign\DatabaseTrigger\Facades\Schema;
Schema::hasTrigger('my_trigger');
use Esign\DatabaseTrigger\Facades\Schema;
Schema::dropTrigger('my_trigger');
Schema::dropTriggerIfExists('my_trigger');
use Esign\DatabaseTrigger\DatabaseTrigger;
use Esign\DatabaseTrigger\Enums\TriggerEvent;
use Esign\DatabaseTrigger\Enums\TriggerTiming;
use Esign\DatabaseTrigger\Facades\Schema;
use Illuminate\Database\Migrations\Migration;
return new class extends Migration
{
public function up(): void
{
Schema::createTrigger('before_posts_update', function (DatabaseTrigger $trigger) {
$trigger->on('posts');
$trigger->timing(TriggerTiming::BEFORE);
$trigger->event(TriggerEvent::UPDATE);
$trigger->statement('');
});
}
public function down(): void
{
Schema::dropTriggerIfExists('before_posts_update');
}
};