PHPackages                             shiftonelabs/laravel-db-events - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. shiftonelabs/laravel-db-events

ActiveLibrary[Database &amp; ORM](/categories/database)

shiftonelabs/laravel-db-events
==============================

Add extra database events.

1.0.0(9y ago)39.0k↓26.7%5MITPHPPHP &gt;=5.4.0

Since Oct 30Pushed 9y ago1 watchersCompare

[ Source](https://github.com/shiftonelabs/laravel-db-events)[ Packagist](https://packagist.org/packages/shiftonelabs/laravel-db-events)[ Docs](https://github.com/shiftonelabs/laravel-db-events)[ RSS](/packages/shiftonelabs-laravel-db-events/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (5)Used By (0)

laravel-db-events
=================

[](#laravel-db-events)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e07f9210ffe1b3a397b3cb649c2cdf6076765291c796f3a5724098eb77547ff0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73686966746f6e656c6162732f6c61726176656c2d64622d6576656e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shiftonelabs/laravel-db-events)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)[![Build Status](https://camo.githubusercontent.com/0389511456bbf726e34715630a573c9802d9587630296d3de65a53b3bbca338a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f73686966746f6e656c6162732f6c61726176656c2d64622d6576656e74732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/shiftonelabs/laravel-db-events)[![Coverage Status](https://camo.githubusercontent.com/48433356e02ebabb3e43e2b260e4dd1beb81b07e5ff85f25c043799642d94ac2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f73686966746f6e656c6162732f6c61726176656c2d64622d6576656e74732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/shiftonelabs/laravel-db-events/code-structure)[![Quality Score](https://camo.githubusercontent.com/5f32e5537e39f135388c3266b71e1414c85dfd0ea1743830135790bb45135606/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f73686966746f6e656c6162732f6c61726176656c2d64622d6576656e74732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/shiftonelabs/laravel-db-events)[![Total Downloads](https://camo.githubusercontent.com/773ae9ff093ac04ea706828e954ac79cb1c0e09335c5d89cf06d09b85a4e2f07/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73686966746f6e656c6162732f6c61726176656c2d64622d6576656e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shiftonelabs/laravel-db-events)

This Laravel/Lumen package provides additional events for the Illuminate Database package. Currently, this package adds:

- a `DatabaseConnecting` event that is fired before connecting to the database, which can modify the configuration or cancel the connection
- a `DatabaseConnected` event that is fired after connecting to the database
- a `ConnectingException` runtime exception that is thrown if the database connection is cancelled by the `DatabaseConnecting` event

Additional events may be added be added as requested/submitted.

Install
-------

[](#install)

Via Composer

```
$ composer require shiftonelabs/laravel-db-events
```

Once composer has been updated and the package has been installed, the service provider will need to be loaded.

For Laravel 4, open `app/config/app.php` and add following line to the providers array:

```
'ShiftOneLabs\LaravelDbEvents\LaravelDbEventsServiceProvider',
```

For Laravel 5, open `config/app.php` and add following line to the providers array:

```
ShiftOneLabs\LaravelDbEvents\LaravelDbEventsServiceProvider::class,
```

For Lumen 5, open `bootstrap/app.php` and add following line under the "Register Service Providers" section:

```
$app->register(ShiftOneLabs\LaravelDbEvents\LaravelDbEventsServiceProvider::class);
```

Usage
-----

[](#usage)

#### DatabaseConnecting Event

[](#databaseconnecting-event)

The `ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnecting` event allows you to hook into the database connection lifecycle before the connection is established. Additionally, this event provides you the ability to modify the configuration used for the connection, as well as completely cancel the connection attempt.

**Attributes**

The `DatabaseConnecting` event provides three public attributes:

AttributeDescription`public $connector`The `Connector` object making the connection. This package extends each of the built-in connectors.`public $connectionName`The name of the selected database connection configuration.`public $config`The configuration array used to connect to the database.Example:

```
app('events')->listen('ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnecting', function ($event) {
    app('log')->info('Connector class: '.get_class($event->connector));
    app('log')->info('Connection name: '.$event->connectionName);
    app('log')->info('Configuration: '.print_r($event->config, true));
});
```

**Modifying Connection Configuration**

The configuration for your database connections is usually stored in your `config/database.php` file (in conjunction with your `.env` file). If, however, you need to dynamically modify the configuration used for the connection, this can be done inside a `DatabaseConnecting` event listener. Any changes made to the configuration in the event listener will be used for the database connection.

Example:

```
app('events')->listen('ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnecting', function ($event) {
    // don't connect to mysql in strict mode if you like zeroed out dates
    if (i_like_zero_dates()) {
        $event->config['strict'] = false;
    }
});
```

**Cancelling the Connection**

There may be situations where you would like to prevent the database from attempting the connection. In this case, the database connection attempt can be cancelled by returning `false` from a `DatabaseConnecting` event listener. If the database connection is cancelled, a `ShiftOneLabs\LaravelDbEvents\Exceptions\ConnectingException` runtime exception will be thrown.

Example:

```
app('events')->listen('ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnecting', function ($event) {
    if (not_todaaay()) {
        return false;
    }
});
```

#### DatabaseConnected Event

[](#databaseconnected-event)

The `ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnected` event allows you to hook into the database connection lifecycle after the connection is established. Additionally, this event provides access to the final configuration used for the connection, as well as the connection itself.

**Attributes**

The `DatabaseConnected` event provides four public attributes:

AttributeDescription`public $connector`The `Connector` object making the connection. This package extends each of the built-in connectors.`public $connectionName`The name of the selected database connection configuration.`public $config`The configuration array that was used to connect to the database.`public $pdo`The connected `PDO` (or potentially `Doctrine\DBAL\Driver\PDOConnection`, as of 5.3) object.Example:

```
app('events')->listen('ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnected', function ($event) {
    app('log')->info('Connector class: '.get_class($event->connector));
    app('log')->info('Connection name: '.$event->connectionName);
    app('log')->info('Configuration: '.print_r($event->config, true));
    app('log')->info('PDO class: '.get_class($event->pdo));
});
```

Contributing
------------

[](#contributing)

Contributions are very welcome. Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Patrick Carlo-Hickman](https://github.com/patrickcarlohickman)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.txt) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3486d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/359fc390650d98265cef526a899c6bc79cd9030e32d17a472af34f38ed70fb2c?d=identicon)[patrickcarlohickman](/maintainers/patrickcarlohickman)

---

Top Contributors

[![patrickcarlohickman](https://avatars.githubusercontent.com/u/6036266?v=4)](https://github.com/patrickcarlohickman "patrickcarlohickman (7 commits)")

---

Tags

laraveldatabaselumenevents

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/shiftonelabs-laravel-db-events/health.svg)

```
[![Health](https://phpackages.com/badges/shiftonelabs-laravel-db-events/health.svg)](https://phpackages.com/packages/shiftonelabs-laravel-db-events)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[mvanduijker/laravel-transactional-model-events

Add eloquent model events fired after a transaction is committed or rolled back

75164.5k](/packages/mvanduijker-laravel-transactional-model-events)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[dragon-code/laravel-data-dumper

Adding data from certain tables when executing the `php artisan schema:dump` console command

3418.6k](/packages/dragon-code-laravel-data-dumper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
