【问题标题】:Fatal error: Class 'Illuminate\Database\Capsule\Manager' not found致命错误:找不到类 'Illuminate\Database\Capsule\Manager'
【发布时间】:2015-10-12 04:47:38
【问题描述】:

我关注phpacademys新的认证教程https://www.youtube.com/watch?v=PF2WkRCZfBg

我有一个类文件database.php:

<?php
use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;

$capsule->addConnection([
 'driver'     => $app->config->get('db.driver'),
 'host'       => $app->config->get('db.host'),
 'database'   => $app->config->get('db.name'),
 'username'   => $app->config->get('db.username'),
 'password'   => $app->config->get('db.password'),
 'charset'    => $app->config->get('db.charset'),
 'collation'  => $app->config->get('db.collation'),
 'prefix'     => $app->config->get('db.prefix')
]);

$capsule->bootEloquent();

但是它抛出了这个错误:

致命错误:第 4 行的 C:\xampp\htdocs\boilerplate\app\database.php 中找不到类“Illuminate\Database\Capsule\Manager”

我在 start.php 中需要它

<?php
require 'database.php';
//############ NAMESPACING ################//
use Slim\Slim; //import slim
use Noodlehaus\Config;
use Boilerplate\User\User;
//#########################################//

session_cache_limiter(false);
session_start();

ini_set('display_errors','on'); //TURN OFF ON LIVE SITE

define('INC_ROOT', dirname(__DIR__)); //create local root

require INC_ROOT . '/vendor/autoload.php'; // autoload in all the      dependencies in the vendor files.

$app = new Slim([
'mode' => file_get_contents(INC_ROOT . '/mode.php')
]); //assign the entire app file to a variable

$app->configureMode($app->config('mode'), function() use ($app){
$app->config = Config::load(INC_ROOT . "/app/config/{$app->mode}.php"); //pull in the config file
});

$app->container->set('user', function(){
    return new User;
});

【问题讨论】:

  • 你是在使用 composer 引入 Illuminate\Database 吗?
  • 是的,这是我的 json 文件 { "autoload": { "psr-4" : { "Boilerplate\\" : "app/Boilerplate" } }, "require": { "slim /slim”:“~2.0”,“slim/views”:“0.1.*”,“phpmailer/phpmailer”:“~5.2”,“hassankhan/config”:“0.8.*”,“twig/twig”: “~1.0”、“照亮/数据库”:“~5.0”、“ircmaxell/random-lib”:“~1.1”}

标签: php laravel eloquent composer-php vendor


【解决方案1】:

确保您已将 Illuminate\Database 添加到您的作曲家文件并运行 composer update

然后在添加自动加载器后输入require 'database.php';

require INC_ROOT . '/vendor/autoload.php';

// Below here

【讨论】:

  • 非常感谢你让我绞尽脑汁一天!
【解决方案2】:

我有同样的错误。在我的情况下,解决方案是使用下一个命令再次安装作曲家:

composer install

如果您使用的是 docker,请在运行安装命令之前确保您在容器内。

docker-compose run <app_name> bash

【讨论】:

    猜你喜欢
    • 2016-12-31
    • 1970-01-01
    • 2015-06-28
    • 2018-09-16
    • 1970-01-01
    • 2023-03-07
    • 2019-05-22
    • 2016-05-26
    • 2019-09-12
    相关资源
    最近更新 更多