{"id":15024176,"url":"https://github.com/ntimyeboah/laravel-database-trigger","last_synced_at":"2025-04-09T20:09:08.562Z","repository":{"id":31273637,"uuid":"126728353","full_name":"NtimYeboah/laravel-database-trigger","owner":"NtimYeboah","description":"Generate migration file for database triggers","archived":false,"fork":false,"pushed_at":"2025-02-24T14:40:26.000Z","size":181,"stargazers_count":20,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T20:09:04.381Z","etag":null,"topics":["database","laravel","mysql","php","trigger"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NtimYeboah.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-25T18:39:27.000Z","updated_at":"2025-02-24T14:42:27.000Z","dependencies_parsed_at":"2024-11-07T11:01:34.219Z","dependency_job_id":"9a4bf180-0480-4af4-8dfb-642c517b2597","html_url":"https://github.com/NtimYeboah/laravel-database-trigger","commit_stats":{"total_commits":66,"total_committers":3,"mean_commits":22.0,"dds":0.06060606060606055,"last_synced_commit":"11dfea36946cbfb87a2fa4458aeb4b5fe34e8b06"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NtimYeboah%2Flaravel-database-trigger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NtimYeboah%2Flaravel-database-trigger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NtimYeboah%2Flaravel-database-trigger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NtimYeboah%2Flaravel-database-trigger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NtimYeboah","download_url":"https://codeload.github.com/NtimYeboah/laravel-database-trigger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103872,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","laravel","mysql","php","trigger"],"created_at":"2024-09-24T19:59:54.197Z","updated_at":"2025-04-09T20:09:08.542Z","avatar_url":"https://github.com/NtimYeboah.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Add database trigger to Laravel migrations\n==========================================\n\n[![Total Downloads](https://img.shields.io/packagist/dt/ntimyeboah/laravel-database-trigger.svg?style=flat-square)](https://packagist.org/packages/ntimyeboah/laravel-database-trigger)\n![Build Status](https://github.com/NtimYeboah/laravel-database-trigger/actions/workflows/tests.yml/badge.svg)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n\n\nLaravel Database Trigger provides a way to add database trigger to laravel migrations just like you would with database table. \nA 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).\n\n\n## Installation\n\nLaravel Database Trigger requires at least [PHP](https://php.net) 8.2. This particular version supports Laravel v11.*. Check the table below for versions support.\n\n| Package version | Laravel version | PHP version |\n|----------|:-------------:|------:|\n| 1 | 5.5, 5.6, 5.7 | \u003e= 7.1 |\n| 2.* | 5.8 | \u003e= 7.1.3 |\n| 3.* | 6.* | \u003e= 7.2.5 or \u003e= 8.0 |\n| 4.* | 7.* | \u003e= 7.2.5 or \u003e= 8.0 |\n| 5.* | 8.* | \u003e= 7.3 or \u003e= 8.0 |\n| 6.* | 9.* | \u003e=8.0 |\n| 7.* | 10.* | \u003e=8.1 |\n| 8.* | 11.* , 12.* | \u003e=8.2 |\n\nThis package currently supports MySQL only.\n\nTo get the latest version, simply require the package using [Composer](https://getcomposer.org):\n\n```bash\ncomposer require ntimyeboah/laravel-database-trigger\n```\n\nOnce installed, if you are not using automatic package discovery, then you need to register the `NtimYeboah\\LaravelDatabaseTrigger\\TriggerServiceProvider` service provider in your `config/app.php`.\n\n\n## Usage\nCreate a trigger migration file using the `make:trigger` artisan command. \nThe command requires the name of the trigger, name of the event object table, action timing and the event that activates the trigger.\n\n```bash\nphp artisan make:trigger after_users_update\n```\n\n### Event object table\nThe event object table is the name of the table the trigger is associated with.\n\n### Action timing\nThe activation time for the trigger. Possible values are `after` and `before`. \n\n`after` - Process action after the change is made on the event object table. \n\n`before` - Process action prior to the change is made on the event object table.\n\n### Event\nThe event to activate trigger. A trigger event can be `insert`, `update` and `delete`.\n\n`insert` - Activate trigger when an insert operation is performed on the event object table.\n\n`update` - Activate trigger when an update operation is performed on the event object table.\n\n`delete` - Activate trigger when a delete operation is performed on the event object table.\n\n\nThe 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.\n\n```php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse NtimYeboah\\LaravelDatabaseTrigger\\TriggerFacade as Schema;\n\nreturn new class extends Migration\n{\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        Schema::create('after_users_update')\n            -\u003eon('users')\n            -\u003estatement(function() {\n                return '//...';\n            })\n            -\u003eafter()\n            -\u003eupdate();\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        Schema::dropIfExists('after_users_update');\n    }\n};\n\n```\n\nReturn the trigger statement from the closure of the `statement` method. \n\nThe following is an example trigger migration to insert into the `users_audit` table after updating a user row.\n\n```php\n\n...\n\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        Schema::create('after_users_update')\n            -\u003eon('users')\n            -\u003estatement(function() {\n                return 'insert into `users_audit` (`name`, `email`) values (old.name, old.email);';\n            })\n            -\u003eafter()\n            -\u003eupdate();\n    }\n\n...\n\n```\n\n## Testing\n\nRun the tests with:\n\n```php\n$ composer test\n```\n\n## Consider hiring me\nI am currently seeking new employment opportunities and would appreciate it if you'd keep me in mind for roles such as Backend Developer.\nKindly contact me at: ntimobedyeboah@gmail.com\n\nThis is a link to my CV: [Ntim Yeboah CV](https://docs.google.com/document/d/1jXVsN1NU5AH2XhStxjuwumGIqunoyk0cPPXZr6viaNs/edit?usp=sharing)\n\n\n## Changelog\n\nPlease see [CHANGELOG](https://github.com/NtimYeboah/laravel-database-trigger/blob/master/CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/NtimYeboah/laravel-database-trigger/blob/master/CONTRIBUTING.md) for details.\n\n\n## Security\n\nIf you discover a security vulnerability within this package, please send an e-mail to Ntim Yeboah at ntimobedyeboah@gmail.com. All security vulnerabilities will be promptly addressed.\n\n\n## License\n\nLaravel Database Trigger is licensed under [The MIT License (MIT)](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntimyeboah%2Flaravel-database-trigger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fntimyeboah%2Flaravel-database-trigger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntimyeboah%2Flaravel-database-trigger/lists"}