Euan T
Euan T

Reputation: 2141

Laravel 4 migrations - class not found

This question is now solved - I used the below:

And, problem solved thanks to IRC. I was told to run

php composer.phar dump-autoload

This fixes the problem for me. It's likely related to my strange Composer setup.


I've just started playing with Laravel 4 for a possible future project, having come from Laravel 3. I have started off by creating a new migration, create_blogs_table using artisan:

php artisan migrate:make create_blogs_table --table=blogs --create

This generated the basic migration file structure which I then filled out a little more:

<?php

use Illuminate\Database\Migrations\Migration;

class CreateBlogsTable extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('blogs', function($table)
        {
            $table->increments('id');
            $table->string('title');
            $table->text('description')->nullable();
            $table->integer('user_id')->unsigned();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('blogs');
    }
}

I now try to run this migration using artisan once again:

php artisan migrate --env=local

*note I have a local database connection set up for domains with the .dev extension

Previously this would work just fine (in Laravel 3) but with Illuminate I then receive this error:

PHP Fatal error:  Class 'CreateBlogsTable' not found in /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php on line 301
PHP Stack trace:
PHP   1. {main}() /var/www/gamingsite/artisan:0
PHP   2. Symfony\Component\Console\Application->run() /var/www/gamingsite/artisan:57
PHP   3. Symfony\Component\Console\Application->doRun() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:106
PHP   4. Illuminate\Console\Command->run() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:193
PHP   5. Symfony\Component\Console\Command\Command->run() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:95
PHP   6. Illuminate\Console\Command->execute() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:240
PHP   7. Illuminate\Database\Console\Migrations\MigrateCommand->fire() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:107
PHP   8. Illuminate\Database\Migrations\Migrator->run() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:69
PHP   9. Illuminate\Database\Migrations\Migrator->runMigrationList() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:75
PHP  10. Illuminate\Database\Migrations\Migrator->runUp() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:106
PHP  11. Illuminate\Database\Migrations\Migrator->resolve() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:125
PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/gamingsite/app/start/../storage/logs/log-2012-12-28.txt" could not be opened: failed to open stream: Permission denied' in /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:71
Stack trace:
#0 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(77): Monolog\Handler\StreamHandler->write(Array)
#1 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\RotatingFileHandler->write(Array)
#2 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Logger.php(214): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#3 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Logger.php(278): Monolog\Logger->addRecord(400, Object(Symfony\Component\HttpKernel\Exception\FatalErrorException), Array)
#4 [internal function]: Monolog\Logger->addError(Object(Symfony\Component\HttpKernel\Exception\FatalErrorExcepti in /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 71
PHP Stack trace:
PHP   1. {main}() /var/www/gamingsite/artisan:0
PHP   2. Symfony\Component\Console\Application->run() /var/www/gamingsite/artisan:57
PHP   3. Symfony\Component\Console\Application->doRun() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:106
PHP   4. Illuminate\Console\Command->run() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:193
PHP   5. Symfony\Component\Console\Command\Command->run() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:95
PHP   6. Illuminate\Console\Command->execute() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:240
PHP   7. Illuminate\Database\Console\Migrations\MigrateCommand->fire() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:107
PHP   8. Illuminate\Database\Migrations\Migrator->run() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:69
PHP   9. Illuminate\Database\Migrations\Migrator->runMigrationList() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:75
PHP  10. Illuminate\Database\Migrations\Migrator->runUp() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:106
PHP  11. Illuminate\Database\Migrations\Migrator->resolve() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:125

I've checked and the database/migrations/ folder is certainly being autoloaded. I have no idea what the cause for this problem may be. Having asked on IRC and googled I'm still completely clueless so hopefully somebody can help me out here.

Thanks in advance!

Upvotes: 26

Views: 17758

Answers (4)

Raftalks
Raftalks

Reputation: 2037

In Laravel 4 (illuminate) migration class do not require you to set unsigned method. You can try this.

  class CreateBlogsTable extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('blogs', function($table)
        {
            $table->increments('id');
            $table->string('title');
            $table->text('description')->nullable();
            $table->integer('user_id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('blogs');
    }
}

After having the chat with you, I knew two problems, one is that already mentioned above and the other problem is due to the class not been registered into composer autoload. You will have to run manually : php composer.phar dump-autoload

Upvotes: 16

user3474709
user3474709

Reputation: 9

Update your composer (composer self-update), then run your composer functions.

Upvotes: -1

Yarco
Yarco

Reputation: 803

Artisan do the same work:

php artisan dump-autoload

Just a reminder for those who are not familiar with composer.

Upvotes: 15

Thomas Clarkson
Thomas Clarkson

Reputation: 755

I had this error on xubuntu and fixed it with sudo composer dump-autoload

Upvotes: 28

Related Questions