zeuxisoo / php-slim-eloquent by zeuxisoo

PHP laravel eloquent on slim framework
1,268
5
1
Package Data
Maintainer Username: zeuxisoo
Maintainer Contact: seekstudio@gmail.com (Zeuxis Lo)
Package Create Date: 2015-05-27
Package Last Update: 2015-05-28
Language: PHP
License: BSD-2-Clause
Last Refreshed: 2024-11-19 03:16:11
Package Statistics
Total Downloads: 1,268
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 5
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Installing

  • Install the composer
curl -sS https://getcomposer.org/installer | php
  • Edit composer.json
{
    "require": {
        "zeuxisoo/slim-eloquent": "0.1.0"
    }
}
  • Install/update your dependencies
php composer.phar install

Usage

  • Create database config
$app->config('databases', [
    'default' => [
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'production',
        'username'  => 'root',
        'password'  => '',
        'charset'   => 'utf8',
        'collation' => 'utf8_general_ci',
        'prefix'    => ''
    ]
]);
  • Add the middleware into slim application
$app->add(new Zeuxisoo\Laravel\Database\Eloquent\ModelMiddleware);

Note

  • If you want multiple database connection, you can change the config like:
$app->config('databases', [
    'default' => [
       'driver'    => 'mysql',
       'host'      => 'localhost',
       'database'  => 'production',
       'username'  => 'root',
       'password'  => '',
       'charset'   => 'utf8',
       'collation' => 'utf8_general_ci',
       'prefix'    => ''
   ],
   'testing' => [
       'driver'    => 'mysql',
       'host'      => 'localhost',
       'database'  => 'testing',
       'username'  => 'root',
       'password'  => '',
       'charset'   => 'utf8',
       'collation' => 'utf8_general_ci',
       'prefix'    => ''
   ]
]);
  • In the application, You can set the connection like:
// Default connection
$connectionDefault     = $app->db->getConnection();
$connectionDefaultUser = $connectionDefault->table('user')->find(1);

// Testing connection
$connectionTesting     = $app->db->getConnection('testing');
$connectionTestingUser = $connectionTesting->table('user')->find(1);

// Model like
$modelDefaultUser = User::find(1);
$modelTestingUser = User::on('testing')->find(1);

Want more information? Please see the examples directory.