2017 © Pedro Peláez
 

library silex-capsule-eloquent

Capsule/Eloquent Service Provider for Silex 2

image

jguyomard/silex-capsule-eloquent

Capsule/Eloquent Service Provider for Silex 2

  • Saturday, December 3, 2016
  • by jguyomard
  • Repository
  • 3 Watchers
  • 7 Stars
  • 7,745 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 5 Versions
  • 12 % Grown

The README.md

Capsule (and Eloquent) Service Provider for Silex 2

Travis StyleCI Packagist Pre Release Licence, (*1)

This is a Service Provider for Silex 2.0.x-dev that integrates Laravel's Fluent Query Builder and Eloquent ORM via Capsule., (*2)

Installation

Note: This Service Provider requires silex/silex ~2.0@dev., (*3)

composer require jguyomard/silex-capsule-eloquent 2.0.x-dev

Usage

This is a basic configuration with MySQL (Currently, Laravel supports MySQL, Postgres, SQLite and SQL Server):, (*4)

$app = new Silex\Application();

$app->register(
    new \JG\Silex\Provider\CapsuleServiceProvider(),
    [
        'capsule.connections' => [
            'default' => [
                'driver'    => 'mysql',
                'host'      => 'localhost',
                'database'  => 'mydatabase',
                'username'  => 'root',
                'password'  => 'root',
            ]
        ]
    ]
);

This is a basic usage, using Query Builder or Raw SQL Queries:, (*5)

$app->get('/article/{id}', function(Application $app, $id)
{
    $article = Capsule::table('article')->where('id', $id)->get();

    // Rest of your code...
});

$app->get('/raw/{id}', function(Application $app, $id)
{
    $article = Capsule::select('SELECT * FROM article WHERE id = :id', [
        'id' => $id,
    ]);

    // Rest of your code...
});

$app->run();

You can also use Eloquent Models:, (*6)

class ArticleModel extends Model
{
    protected $table = 'article';

    protected $primaryKey = 'id';

    protected $fillable = [
        'title'
    ];

    // Rest of your code...
}

$app->get('/article/{id}', function(Application $app, $id)
{
    $article = ArticleModel::find($id);

    // Rest of your code...
});

$app->post('/article', function(Application $app)
{
    $article = ArticleModel::create([
        'title' => 'Foo'
    ]);

    // Rest of your code...
});

$app->run();

For further documentation on using the various database facilities this library provides, consult the Laravel framework database documentation., (*7)

Configuration

This is a complete configuration example, with multiple connections:, (*8)

$app = new Silex\Application();

$app->register(
    new \JG\Silex\Provider\CapsuleServiceProvider(),
    [
        'capsule.connections' => [
            'default' => [
                'driver'    => 'mysql',
                'host'      => 'localhost',
                'port'      => 3306,
                'database'  => 'mydatabase',
                'username'  => 'root',
                'password'  => 'root',
                'charset'   => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix'    => '',
                'strict'    => false,
                'engine'    => null,
            ],
            'pgsql' => [
                'driver' => 'pgsql',
                'host'      => 'localhost',
                'port'      => 5432,
                'database'  => 'mydatabase',
                'username'  => 'root',
                'password'  => 'root',
                'charset'   => 'utf8',
                'prefix'    => '',
                'schema'    => 'public',
            ],
            'sqlite' => [
                'driver' => 'sqlite',
                'database'  => 'mydatabase',
                'prefix' => '',
            ],
        ],
        'capsule.options' => [
            'setAsGlobal'    => true,
            'bootEloquent'   => true,
            'enableQueryLog' => true,
        ],
    ]
);

Testing

To run the test suite, you need PHPUnit:, (*9)

phpunit

Credits

Inspired by illuminate-database-silex-service-provider (for Silex 1.*) and saxulum-doctrine-mongodb-odm-provider@dev (Mongodb ODM for Silex 2.0.x-dev)., (*10)

Issues

If you have any problems with or questions about this Service Provider, please contact me through a GitHub issue. If the issue is related to Capsule itself please leave an issue on Laravel official repository., (*11)

Contributing

You are invited to contribute new features, fixes or updates to this container, through a Github Pull Request., (*12)

The Versions

03/12 2016

2.0.x-dev

2.0.9999999.9999999-dev

Capsule/Eloquent Service Provider for Silex 2

  Sources   Download

MIT

The Requires

 

by Julien Guyomard

laravel sql eloquent query capsule

21/10 2016

v2.0.2

2.0.2.0

Capsule/Eloquent Service Provider for Silex 2

  Sources   Download

MIT

The Requires

 

by Julien Guyomard

laravel sql eloquent query capsule

11/10 2016

v2.0.1

2.0.1.0

Capsule/Eloquent Service Provider for Silex 2

  Sources   Download

MIT

The Requires

 

by Julien Guyomard

laravel sql eloquent query capsule

11/10 2016

dev-master

9999999-dev

Capsule/Eloquent Service Provider for Silex 2

  Sources   Download

MIT

The Requires

 

by Julien Guyomard

laravel sql eloquent query capsule

26/06 2016

v2.0.0

2.0.0.0

Capsule/Eloquent Service Provider for Silex 2

  Sources   Download

MIT

The Requires

 

by Julien Guyomard

laravel sql eloquent query capsule