Hi,
create new project with sandbox
composer create-project adriansuter/slim4-skeleton [my-app-name]
Database depedencies
use Illuminate\Database\Capsule\Manager as Capsule;
$containerBuilder->addDefinitions([
Capsule::class => function(ContainerInterface $c) {
$capsule = new Capsule();
$capsule->addConnection($c->get(‘settings’)[‘db’]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
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();
$capsule->addConnection([
'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')
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
//// 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 