I'm also using Capsule with Slim. First off, make sure that you're using version 4.1.* of Illuminate/Capsule. When 4.2 came out, one of the big changes was that PHP 5.4 became the required minimum. 4.1 will still work with PHP 5.3.
Now, if you've done that and you're still running into problems, this is how I registered capsule with Slim's IoC container:
$app->container->singleton('capsule', function() use ($config) {
$capsule = new Illuminate\Database\Capsule\Manager;
$capsule->setFetchMode(PDO::FETCH_OBJ);
$capsule->addConnection($config['database']);
$capsule->bootEloquent();
return $capsule->getConnection();
});
Note the call to getConnection()
. This is necessary, as the Capsule global is not getting registered.
Edit: Also note the call to setFetchMode
. When using Fluent from within Laravel, queries return instances of stdClass, but the default behavior appears to be to return associative arrays. The framework just overrides that at some point, leading to Capsule behaving in correct, yet unexpected ways. This sets it to run with more expected behavior.