Hi all,

Im starting to use composer, and have installed a few packages - This thread is about illuminate/database component.

Im clearly misunderstanding something about how i can use the autoloader.

I have the following directory structure:

index.php [Request goes to index.php] - This file includes composers autoloader (psr-4)

Inside -app, I have this structure:

----database [containing database.php]

So, in the index.php file i first include the autoloader, then I require('app/framework/core/database/database.php')

In database.php I have this

use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;

'driver'    => 'mysql',
'host'      => DB_HOST,
'database'  => DB_NAME,
'username'  => DB_USER,
'password'  => DB_PASS,
'charset'   => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix'    => '',

// Make this Capsule instance available globally via static methods

// Setup the Eloquent ORM

This gives me the following error in index.php on page load:

Fatal error: Class 'Capsule' not found in C:\wamp\www\framework\index.php on line 26

If I insert the above database setup code directly in index.php, it all works fine. But when I have it in an included file, the autoloader doesnt know of the class. The file is included properly, the path is ok as I can echo out stuff.

My composer.json in root looks like this:

"name": "Dev/framework",
"description": "MVC framework - All the good stuff from the MVC design pattern..",
"license": "MIT",
"authors": [
        "name": "Jan Klemmensen",
        "email": "xx@hotmail.com"
"require": {
    "swiftmailer/swiftmailer": "5.3.*@dev", 
    "imagine/imagine": "dev-master",
    "illuminate/database": "4.0.*",
    "illuminate/cache": "4.0.*",
    "illuminate/filesystem": "4.0.*",
    "illuminate/validation": "4.0.*" 
"autoload": {
    "psr-4": {
        "App\\": "app/"

Is there any composer experienced folks out there, that can point me in the right direction on how to instantiate the vendor illuminate from inside my app directory. I would like to seperate the vendor packages from the system specific config.

I thought that by including the file, it would be the same as if it was written into the file directly..

Any thoughts appreciated,

Edited by klemme

3 Years
Discussion Span
Last Post by klemme

Found out why...

In the database file being included i had this at first:

use Illuminate\Database\Capsule\Manager as Capsule;

But this apparently doesnt take effect in the file that is including it.

So by writing

use Illuminate\Database\Capsule\Manager as Capsule;

In index.php (For test only, as it would be used in models later on) - It all works fine.

So for anyone hitting this wall, that could be a way to deal with it..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.