0

print_r(Auth::user());在容器注入功能中使用,但这里容器功能不允许

 $user=Auth::user();

 print_r($user);

我的主要容器功能代码。

      protected static function _makeContainer() 
        {
          $user=Auth::user();
          print_r($user);
          die;
          $config = Config::cache();
          $dbConfig = $config['database'];
          // Create our new php-di container
          $builder = new ContainerBuilder();
          $builder->useAutowiring(true);
          $builder->addDefinitions([
            'config'            => $config,
            PDO::class          => di_autowire()->constructor(
                "mysql:host={$dbConfig['host']};dbname={$dbConfig['database']}",
                $dbConfig['username'],
                $dbConfig['password'],
                ['ATTR_DEFAULT_FETCH_MODE' => PDO::FETCH_OBJ]
            ),
            PHPMailer::class    => di_autowire()->constructor(true),
            'Simcify\Mailer'    => factory(function($mail) {
                $mail->SMTPDebug = 0;
                $mail->isSMTP();
                $mail->Host = env('SMTP_HOST');
                $mail->SMTPAuth = env("SMTP_AUTH");
                $mail->Username = env('MAIL_USERNAME');
                $mail->Password = env('SMTP_PASSWORD');
                $mail->SMTPSecure = env('MAIL_ENCRYPTION');
                $mail->Port = env('SMTP_PORT');
                return $mail;
            })->parameter('mail', get('PHPMailer\PHPMailer\PHPMailer')),
            Session::class      => di_autowire()
        ]);
        
        Container::setInstance($builder->build());
     }

我想根据用户会话使用动态连接字符串。

4

0 回答 0