objective-php/eloquent-package

Eloquent ORM integration from Laravel for Objective PHP

dev-master 2016-05-06 22:28 UTC

This package is not auto-updated.

Last update: 2024-12-07 20:17:16 UTC


README

Project topic

This package add seamless integration for Eloquent ORM (native Laravel ORM).

It mainly allows configuring a connection to the database and registering the capsule as global, which is enough for creating and using Eloquent's style models in the application.

How to make it work

Install the package

Use composer to import the package in your application:

# cd to your project root, where is the composer.json file stored
composer require objective-php/eloquent-package dev-master 

Activate it

You have to plug the package Middleware to your application to activate it:

use ObjectivePHP\Application\ApplicationInterface;
use ObjectivePHP\EloquentPackage\EloquentPackage;

class Application extends ApplicationInterface
{
    public function init()
    {
        // ...
        
        // plug Eloquent package to any requests
        //
        // add some filter as extra plug() parameters to condition package actual activation 
        $this->on('bootstrap')->plug(new EloquentPackage());
        
        // ...
    }
}

Configure it

In order to make Eloquent fully functional, you have to define a database connection. This configuration has to be done in the application configuration. When using Objective PHP starter kit, all you have to do is to create a config file in the app/config folder, name it whathever you want (but eloquent.php seems to be a decent name for this purpose :)) and then return a config array like the following:

return
    [
        'eloquent.driver'          => 'mysql',
        'eloquent.host'            => '127.0.0.1',
        'eloquent.username'        => /* user name */,
        'eloquent.password'        => /* plain text password */,
        'eloquent.database'        => /* database name */
        // 'eloquent.charset'      => /* defaults to 'utf8' */,
        // 'eloquent.collation'    => /* defaults to 'utf8_unicode_ci' */
    ];