Closed NtimYeboah closed 6 years ago
The current API looks OK to me.
Though, instead of after()->update()
and before()->update()
, they can be collapsed into;
before* group such as beforeUpdate()
, beforeInsert()
, beforeDelete()
etc.
Schema::create('before_employees_update, 'employees', function(QueryStatement $query) {
$query->insert('employees_audit', function() {
return 'first_name=old.first_name';
})
})->beforeUpdate();
after* group such as afterDelete()
, afterInsert()
etc.
Schema::create('after_orders_update', 'employees', function(QueryStatement $query) {
$query->statement(function() {
return "delete from orders where status = 'pending'";
})
})->afterUpdate()
@faddai That is a good one, it will be added to the API.
@faddai I have changed the trigger API to the following.
Schema::create('after_users_update')
->on('users')
->statement(function() {
return 'insert into `users_audit` (`name`, `email`) values (old.name, old.email);';
})
->after()
->update();
There will only be one method statement
which will be used to run insert, update and arbitrary statements.
Description:
Currently, the trigger api has 3 methods:-
insert
,update
andstatement
insert
- Run statements to insert into a table when a trigger is calledupdate
- Run statements to update a table when a trigger is calledstatement
- Run arbitrary sql statements when trigger is calledCan the API be simplified, do we need to add or take away some methods?