laravel 致命错误:找不到类“Illuminate\Database\Capsule\Manager”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31560951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:00:21  来源:igfitidea点击:

Fatal error: Class 'Illuminate\Database\Capsule\Manager' not found

phplaraveleloquentcomposer-phpvendor

提问by tom Bannister

Im follow phpacademys new authentication tutorial https://www.youtube.com/watch?v=PF2WkRCZfBg

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

i have a class file database.php:

我有一个类文件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();

however it throws up this error:

但是它抛出了这个错误:

Fatal error: Class 'Illuminate\Database\Capsule\Manager' not found in C:\xampp\htdocs\boilerplate\app\database.php on line 4

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

i have required it in start.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;
});

采纳答案by nathanmac

Make sure you've added Illuminate\Databaseto you're composer file and run composer update

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

Then put require 'database.php';after you're adding the autoloader

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

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

// Below here

回答by Puje

I had the same error. In my case the solution was to install composer again with the next command:

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

composer install

If you are using docker, make sure that you are inside the container before run the install command.

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

docker-compose run <app_name> bash