Slim 4 - Eloquent not working


create new project with sandbox

composer create-project adriansuter/slim4-skeleton [my-app-name]

Database depedencies

use Illuminate\Database\Capsule\Manager as Capsule;

Capsule::class => function(ContainerInterface $c) {
$capsule = new Capsule();

  return $capsule;


But not working, message report is:

[Call to a member function connection() on null]

On version slim 3 working, but here not

Please help thank u

Hi The way that I have it setup is that i have a separate file that boots it and then I add the capsule to the container.

//// DB file
use Illuminate\Database\Capsule\Manager AS Capsule;

$capsule = New Capsule();

    'driver'    => getenv('DB_DRIVER'),
    'host'      => getenv('DB_HOST'),
    'database'  => getenv('DB_DATABASE'),
    'username'  => getenv('DB_USERNAME'),
    'password'  => getenv('DB_PASSWORD'),
    'charset'   => getenv('DB_CHARSET'),
    'collation' => getenv('DB_COLLATION'),
    'prefix'    => getenv('DB_PREFIX') != '' ? getenv('DB_PREFIX') : '' ,
    'port'      => getenv('DB_PORT')



//// container file
require_once APP_ROOT . '/DB/database.php';

// DB
$container->set('db', function () use ($capsule){
    return $capsule;

Thank you very much… it’s work… have a nice day :slight_smile: