Help with .env file and config\settings.php

Hi there.
Can I ask for help.
I have set up a .env file with mysql creds.
I am looking to pull this into config\settings.
I do not see how this is done in Slim 4 framework.
Also I see config\env.example.php but this asks for the username and password to be hard coded.

Below is what I see in Slim 4 framework: config\settings. I.e. I want to get away from hard coding my password and username for the mysql settings.

Hope you can help. Thanks in advance.

  <?php
  // Detect environment
  $_ENV['APP_ENV'] ??= $_SERVER['APP_ENV'] ?? 'dev';

  // Load default settings
 $settings = require __DIR__ . '/defaults.php';

  // Overwrite default settings with environment specific local settings
  $configFiles = [
 __DIR__ . sprintf('/local.%s.php', $_ENV['APP_ENV']),
 __DIR__ . '/env.php',
 __DIR__ . '/../../env.php',
];
  // Database settings
  $settings['db'] = [
  'driver' => 'pdo_mysql',
  'host' => 'localhost',
  'dbname' => 'slimapp',
  'user' => 'myusername',
  'password' => 'mypassword',
   'charset' => 'utf8mb4',

Hi there.
I figured out how to do this.

In config/bootstrap.php

   <?php
   use DI\ContainerBuilder;
   use Slim\App;
   require_once __DIR__ . '/../vendor/autoload.php';
   // Looing for .env at the root directory
   $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../', '.env');   <<<<
  $dotenv->load();    <<<<<<
   //// Retrive env variable  / testing above is working...
    //$userName = $_ENV['DB_NAME'];
     //
    //var_dump($userName);

Then in config/settings.php

    // Overwrite default settings with environment specific local settings
    $configFiles = [
   __DIR__ . sprintf('/local.%s.php', $_ENV['APP_ENV']),
    __DIR__ . '/env.php',
    __DIR__ . '/../../env.php',
    ];

     // Database settings
    $settings['db'] = [
     'driver' => 'pdo_mysql',
      'host' => $_ENV['DB_HOST'],   <<<
      'dbname' => $_ENV['DB_NAME'],  <<<
        'user' => $_ENV['DB_USER'], <<<
         'password' => $_ENV['DB_PASS'],  <<<
      'charset' => 'utf8mb4',