Laravel 4 migrations - class not found

17,674

Solution 1

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

Solution 2

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

Solution 3

Artisan do the same work:

php artisan dump-autoload

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

Share:
17,674

Related videos on Youtube

Euan T
Author by

Euan T

Updated on September 15, 2022

Comments

  • Euan T
    Euan T about 1 year

    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!

  • Euan T
    Euan T almost 11 years
    Just tried that and still no luck. I still get the class not found error.
  • Rob
    Rob about 10 years
    had same problem, running php composer.phar dump-autoload worked.
  • developerbmw
    developerbmw over 8 years
    This is actually better than using composer, as it generates an optimized classmap
  • IIllIIll
    IIllIIll almost 8 years
    Actually this command didn't exist for me but composer dump-autoload solved the problem. Thanks! For the idea, at least.
  • Yarco
    Yarco over 7 years
    Those who search the problem, please noticed that this question is 3 years ago and the version of laravel is 4. And the software itself is keeping changing. It means, this command does't exist in latest artisan. Thank you.