Query Events (Query Builder 14)
Query event
The callback of the database operation is also called the query event. It is a callback method designed for the CURD operation of the database. It mainly includes:
Event | Description |
---|---|
select Callback before query | |
findCallback before query | |
insertCallback after successful operation | |
updateCallback after successful operation | |
deleteCallback after successful operation |
\think\facade\Db::event('before_select', function ($query) { // 事件处理 return $result; });The same query event can register multiple response executions. Query events have also been taken over by the event system in the new version, so if you register a before_select query event listener, the bottom layer actually registers a listener for the event identified as db.before_select. There is only one method parameter for query events: the current query object. But you can add additional parameters through dependency injection.