Giter Club home page Giter Club logo

eloquent-bootstrap's Introduction

Eloquent ORM standalone Bootstrap

Maintainability FOSSA Status

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

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

declare(strict_types=1);

namespace NorthernLights\EloquentBootstrap\Example;

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

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

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

$database->addConnection(
    new Connection('second-database', new ConfigProvider([
        ConfigOptions::HOST     => 'localhost',
        ConfigOptions::DATABASE => 'second_database',
        ConfigOptions::USERNAME => 'second_user',
        ConfigOptions::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

RAW Query usage

<?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

declare(strict_types=1);

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-12 Standard

Library strives to comply with PSR-12 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.

FOSSA Status

eloquent-bootstrap's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar fossabot avatar xzero707 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.