Skip to content
This repository has been archived by the owner on Apr 10, 2019. It is now read-only.

xZero707/eloquent-bootstrap-php56

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eloquent ORM standalone Bootstrap

Maintainability

The Eloquent ORM that comes with Laravel makes it incredibly easy to interact with a database.

Unfortunately, if you want to use it standalone, without rest of framework, things are not so easy.

This library solves that headache for you, and brings Eloquent ORM to your project with single command.

Install

Via Composer

$ composer require northern-lights/eloquent-bootstrap

It really is that easy!

Usage - Single connection

<?php

namespace NorthernLights\EloquentBootstrap\Example;

use NorthernLights\EloquentBootstrap\Database;
use NorthernLights\EloquentBootstrap\Provider\ConfigProvider;

require __DIR__ . '/vendor/autoload.php';

$database = new Database(new ConfigProvider([
        'host'     => 'localhost',
        'database' => 'database_name',
        'username' => 'user',
        'password' => 'pass'
]));

// At this point, eloquent will boot
$database->init();

Usage - Multiple connections

<?php

namespace NorthernLights\EloquentBootstrap\Example;

use NorthernLights\EloquentBootstrap\Connection;
use NorthernLights\EloquentBootstrap\Database;
use NorthernLights\EloquentBootstrap\Provider\ConfigProvider;

require __DIR__ . '/vendor/autoload.php';

$database = new Database();
$database->addConnection(
    new Connection('first-database', new ConfigProvider([
        'host'     => 'localhost',
        'database' => 'first_database',
        'username' => 'user',
        'password' => 'pass'
    ]))
);

$database->addConnection(
    new Connection('second-database', new ConfigProvider([
        'host'     => 'localhost',
        'database' => 'second_database',
        'username' => 'user',
        'password' => 'pass'
    ]))
);

// At this point, eloquent will boot
$database->init();

And that's all you need to include in your bootstrap file. For everything else, consult with Eloquent documentation.

Note: Even in this example, you can setup default connection via Database constructor.

Note: NorthernLights\EloquentBootstrap\Database::getCapsule() will return Capsule instance, which can be used to add connections directly

Creating a simple model

<?php

namespace NorthernLights\EloquentBootstrap\Example;

use NorthernLights\EloquentBootstrap\Model as EloquentModel;

/**
 * Class Users
 * @package NorthernLights\EloquentBootstrap\Example
 */
class Users extends EloquentModel
{
    /** @var string  */
    protected $table = 'users';
}

Note the usage of NorthernLights\EloquentBootstrap\Model, since it will only fix IDE annotations (Confirmed: PhpStorm). It doesn't include any logic.

PSR-2 Standard

Library strives to comply with PSR-2 coding standards, therefore we included following commands:

$ composer check-style
$ composer fix-style

Note: Second command will actually modify files

PSR-4 Standard

Library complies with PSR-4 autoloading standard

Testing

$ composer php-lint
$ composer test

License

The MIT License (MIT). Please see License File for more information.

About

Bootstrap for standalone Eloquent ORM (PHP5.6 only)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%