2017 © Pedro Peláez
 

library eloquent-bootstrap-php56

Bootstrap for standalone Eloquent ORM (PHP5.6 version)

image

northern-lights/eloquent-bootstrap-php56

Bootstrap for standalone Eloquent ORM (PHP5.6 version)

  • Wednesday, April 18, 2018
  • by xZero707
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 11 % Grown

The README.md

Eloquent ORM standalone Bootstrap

Maintainability, (*1)

The Eloquent ORM that comes with Laravel makes it incredibly easy to interact with a database., (*2)

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

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

Install

Via Composer, (*5)

``` bash $ composer require northern-lights/eloquent-bootstrap, (*6)

It really is that easy!

## Usage - Single connection
``` php
<?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 <?php, (*7)

namespace NorthernLights\EloquentBootstrap\Example;, (*8)

use NorthernLights\EloquentBootstrap\Connection; use NorthernLights\EloquentBootstrap\Database; use NorthernLights\EloquentBootstrap\Provider\ConfigProvider;, (*9)

require DIR . '/vendor/autoload.php';, (*10)

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

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

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

And that's all you need to include in your bootstrap file.
For everything else, consult with [Eloquent documentation](https://laravel.com/docs/5.6/eloquent).

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
<?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., (*14)

PSR-2 Standard

Library strives to comply with PSR-2 coding standards, therefore we included following commands: ``` bash $ composer check-style $ composer fix-style, (*15)

Note: Second command will actually modify files

## PSR-4 Standard
Library complies with PSR-4 autoloading standard

## Testing

``` bash
$ composer php-lint
$ composer test

License

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

The Versions