Using Eloquent with Slim

    Figure 1: Add Eloquent to your application.
    1. return [
    2. 'settings' => [
    3. 'determineRouteBeforeAppMiddleware' => false,
    4. 'displayErrorDetails' => true,
    5. 'db' => [
    6. 'driver' => 'mysql',
    7. 'host' => 'localhost',
    8. 'username' => 'user',
    9. 'password' => 'password',
    10. 'charset' => 'utf8',
    11. 'collation' => 'utf8_unicode_ci',
    12. ]
    13. ],
    14. ];
    Figure 2: Settings array.
    Figure 3: Configure Eloquent.
    1. $container[App\WidgetController::class] = function ($c) {
    2. $view = $c->get('view');
    3. $logger = $c->get('logger');
    4. $table = $c->get('db')->table('table_name');
    5. return new \App\WidgetController($view, $logger, $table);
    6. };
    Figure 4: Pass table object into a controller.
    Figure 5: Sample controller querying the table.
    1. ...
    Figure 6: Query searching for names matching foo.

    Query the table by id

    Figure 7: Selecting a row based on id.