致命错误:Class' Illuminate \ Database \ Capsule \ Manager'未找到

时间:2015-07-22 10:48:16

标签: php laravel eloquent composer-php vendor

我关注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();

然而它引发了这个错误:

致命错误:Class&#39; Illuminate \ Database \ Capsule \ Manager&#39;在第4行的C:\ xampp \ htdocs \ boilerplate \ app \ database.php中找不到

我在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;
});

2 个答案:

答案 0 :(得分:1)

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

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

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

// Below here

答案 1 :(得分:0)

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

composer install

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

docker-compose run <app_name> bash