Skip to content

add enable events dispatcher support #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -48,6 +48,31 @@ $resolver = new Illuminate\CodeIgniter\CodeIgniterConnectionResolver($ci);
Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
```

To enable events dispatcher support:

```php
// use our mock PDO class if PDO is not enabled on this server
if (!class_exists('PDO')) {
class_alias('Illuminate\CodeIgniter\FakePDO', 'PDO');
}

// pass all Laravel database queries through to CodeIgniter
$ci = get_instance();
$resolver = new Illuminate\CodeIgniter\CodeIgniterConnectionResolver($ci);

// create a new event dispatcher instance
$event_dispatcher = new Illuminate\Events\Dispatcher();
//create a new database manager instance
$database_manager = new Illuminate\Database\Capsule\Manager();
// attach the evebt dispatcher instance to the manager instance
$database_manager->setEventDispatcher($event_dispatcher);
// attach the event dispatcher to the eloquent
$database_manager->bootEloquent();

Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
```


## License

[MIT License](https://github.com/expressodev/laravel-codeigniter-db/blob/master/LICENSE)