Laravel 迁移:“未找到"类 [英] Laravel migrations: Class "not found"

查看:55
本文介绍了Laravel 迁移:“未找到"类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Laravel 准系统项目部署到 Microsoft Azure,但是每当我尝试执行 php artisan migrate 时,我都会收到错误消息:

I am deploying a Laravel barebone project to Microsoft Azure, but whenever I try to execute php artisan migrate I get the error:

[2015-06-13 14:34:05] production.ERROR: 异常 'SymfonyComponentDebugExceptionFatalErrorException' 在 D:homesitevendor 中出现消息 'Class '' not found'laravelframeworksrcIlluminateDatabaseMigrationsMigrator.php:328

[2015-06-13 14:34:05] production.ERROR: exception 'SymfonyComponentDebugExceptionFatalErrorException' with message 'Class '' not found' in D:homesitevendorlaravelframeworksrcIlluminateDatabaseMigrationsMigrator.php:328

堆栈跟踪:

 #0 {main}  

可能是什么问题?非常感谢

What could be the problem? Thank you very much

迁移类

<?php
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

class CreateUsersTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function(Blueprint $table)
        {
            $table->bigIncrements('id');
            $table->string('name', 50);
            $table->string('surname', 50);
            $table->bigInteger('telephone');
            $table->string('email', 50)->unique();
            $table->string('username', 50)->unique();
            $table->string('password', 50);
            $table->boolean('active')->default(FALSE);
            $table->string('email_confirmation_code', 6);
            $table->enum('notify', ['y', 'n'])->default('y');
            $table->rememberToken();
            $table->timestamps();
            
            $table->index('username');
        });
    }

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

推荐答案

对于 PSR-4 自动加载器用户 (composer.json):

将迁移文件夹保存在 classmap 数组中,不要将其包含在 autoload 头下的 psr-4 对象中.由于迁移的主类 Migrator 不支持命名空间.例如;

Keep the migrations folder inside classmap array and do not include it inside psr-4 object under autoload head. As migrations' main class Migrator doesn't support namespacing. For example;

"autoload": {
    "classmap": [
        "app/database/migrations"
    ],
    "psr-4": {
        "Acme\controllers\": "app/controllers"
    }
}

然后运行:

php artisan clear-compiled 
php artisan optimize:clear
composer dump-autoload
php artisan optimize

  • 第一个清除所有已编译的自动加载文件.
  • 第二次清除 Laravel 缓存(可选)
  • Third 为命名空间类构建自动加载器.
  • Fourth 优化了 Laravel 应用程序的各个部分,并为非命名空间类构建自动加载器.
  • 从现在起,您将不必再次执行此操作,任何新的迁移都将正常工作.

    From this time on wards, you will not have to do this again and any new migrations will work correctly.

    这篇关于Laravel 迁移:“未找到"类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆