nafisc/simple-eloquent

A wrapper for Eloquent directed at simpler implementations.

v1.0 2019-01-10 17:33 UTC

This package is auto-updated.

Last update: 2024-11-11 15:22:31 UTC


README

SimpleEloquent is a wrapper around Eloquent that makes common practices a little easier.

StyleCI Latest Stable Version Total Downloads Latest Unstable Version License

Installation

SimpleEloquent is available through composer.

composer require nafisc/simple-eloquent

Usage

Initializing a Connection

    use \SimpleEloquent\Connection;
    
    $connection = Connection::set (

        // Connection Name
        'test', 

        // Configuration
        [
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'test',
            'username'  => 'root',
            'password'  => 'password',
        ]

    );

Executing Sql / Accessing Eloquent Connection

    // Retrieve the Connection
    $connection = Connection::get('test');

    // Execute some Sql
    $result = $connection->select('SELECT * FROM `servers` LIMIT 1');
    $server = $result[0];
    echo $server->ipv4.PHP_EOL;

    . . . 

    // Alternately, you can access the eloquent
    // connection object directly.
    $connection = Connection::get('test')->eloquentConnection();
    $result = $connection->select('SELECT * FROM `servers` LIMIT 1');

Using Models

    // Retrieve the connection.
    $connection = Connection::get('test');

    // Create a new model for the table 'servers'.
    // See \SimpleEloquent\Connection@model function for more documentation.
    $model = $connection->model('servers');

    // Retrieve a result.
    $result = $model->where('id', 2)->first();
    echo $result->ipv4.PHP_EOL;