2017 © Pedro Peláez
 

library eloquent-bootstrap

Bootstrap for standalone Eloquent ORM

image

northern-lights/eloquent-bootstrap

Bootstrap for standalone Eloquent ORM

  • Wednesday, April 18, 2018
  • by xZero707
  • Repository
  • 1 Watchers
  • 0 Stars
  • 56 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 4 % Grown

The README.md

Eloquent ORM standalone Bootstrap

Maintainability FOSSA Status, (*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

declare(strict_types=1);

namespace NorthernLights\EloquentBootstrap\Example;

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

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

$database = new Database(new ConfigProvider([
        ConfigOptions::HOST     => 'localhost',
        ConfigOptions::DATABASE => 'database_name',
        ConfigOptions::USERNAME => 'user',
        ConfigOptions::PASSWORD => 'pass'
]));

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

Usage - Multiple connections

``` php <?php, (*7)

declare(strict_types=1);, (*8)

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

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

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

$database = new Database(); $database->addConnection( new Connection('first-database', new ConfigProvider([ ConfigOptions::HOST => 'localhost', ConfigOptions::DATABASE => 'first_database', ConfigOptions::USERNAME => 'user', ConfigOptions::PASSWORD => 'pass' ])) );, (*12)

$database->addConnection( new Connection('second-database', new ConfigProvider([ ConfigOptions::HOST => 'localhost', ConfigOptions::DATABASE => 'second_database', ConfigOptions::USERNAME => 'second_user', ConfigOptions::PASSWORD => 'pass' ])) );, (*13)

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

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

## RAW Query usage

``` php
<?php

(...)
// Notice that you need this line too
$database->getCapsule()->setAsGlobal();

$user = DB::table('users')->where('userid', '=', '123');

dump($user);

Creating a simple model

``` php <?php, (*15)

declare(strict_types=1);, (*16)

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

use NorthernLights\EloquentBootstrap\Model as EloquentModel;, (*18)

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

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

## PSR-12 Standard
Library strives to comply with PSR-12 coding standards, therefore we included following commands:
``` bash
$ composer check-style
$ composer fix-style

Note: Second command will actually modify files, (*20)

PSR-4 Standard

Library complies with PSR-4 autoloading standard, (*21)

Testing

bash $ composer php-lint $ composer test, (*22)

License

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

FOSSA Status, (*24)

The Versions

15/03 2018

dev-dependabot/composer/phpunit/phpunit-tw-6.5|tw-7.0

dev-dependabot/composer/phpunit/phpunit-tw-6.5|tw-7.0

Bootstrap for standalone Eloquent ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

15/03 2018

dev-dependabot/composer/phpunit/php-invoker-tw-1.1|tw-2.0

dev-dependabot/composer/phpunit/php-invoker-tw-1.1|tw-2.0

Bootstrap for standalone Eloquent ORM

  Sources   Download

MIT

The Requires

 

The Development Requires