Database

Tomahawk comes with 2 choices of database services, Illuminate Database (Laravel) and Doctrine, each one has its own config that needs to be setup.


Illuminate Database

From Laravel's Github:

"The Illuminate Database component is a full database toolkit for PHP, providing an expressive Query Builder, ActiveRecord style ORM, and Schema Builder. It currently supports MySQL, Postgres, SQL Server, and SQLite."

Configuration

If you are not using the Illuminate Database service you will need to set enabled in the app/config/database.php file to false.

Open app/config/database.php in a text editor.

Here you can set your default connection as well as adding in all your connections. Below is an example of what your config might look like:


Using Eloquent

Make sure you have Tomahawk\Database\DatabaseManager passed in as loading this from the service container will 'boot' Eloquent. You can then use your Eloquent models as normal.


Using Illuminate Query Builder

Make sure you have Tomahawk\Database\DatabaseManager passed in as loading this from the service container will 'boot' Eloquent as well as all connections for use with the Query Builder.

If your Controllers extends Tomahawk\Routing\Controller then you then have access to it through $this->database.

You can then query as if you are using the DB:


Doctrine

The Doctrine service provides a Object Relational Mapper (ORM) and the Database Abstraction Layer (DBAL).

Configuration

If you are not using the Illuminate Database service you will need to set enabled in the app/config/database.php file to false.

Open app/config/doctrine.php in a text editor. Doctrine has more options than Illuminate as it is more configurable.

Here you can set your default connection, all your connections, caching, mapping format and directory.

Below is an example of what your config might look like:

Using Doctrine

Getting an Doctrine Registry

To get the Doctrine Registry where the EntityManager is stored just access your container as below:


Getting the Entity Manager

To retrieve the Entity Manager you would do the following:


Getting an Entity Repository

To retrieve a Repository for an Entity you would do the following:

You can then use it like you normally would. e.g.