Laravel - 运行迁移时未找到类

时间:2018-05-26 13:00:21

标签: php laravel laravel-5

我想运行迁移以将设施列添加到我的图像表中,但它会带来此错误

 Already: No such file or directory
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating optimized autoload files
  

照亮\基金会\ ComposerScripts :: postAutoloadDump   @php工匠包:发现   发现包:fideloper / proxy   发现包裹:nunomaduro /碰撞   发现包裹:laravel / tinker   发现包:uxweb / sweet-alert   发现包:yajra / laravel-datatables-oracle   包清单生成成功。

  Symfony\Component\Debug\Exception\FatalThrowableError  : Class          'AddFacilitiesToImagesNew' not found

 at     /var/www/roomhub/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:418
414|     public function resolve($file)
415|     {
416|         $class = Str::studly(implode('_', array_slice(explode('_', $file), 4)));
417|
  

418 |返回新的$ class;       419 | }       420 |       421 | / **       422 | *获取给定路径中的所有迁移文件。

Exception trace:

 1       Illuminate\Database\Migrations\Migrator::resolve("2018_05_26_085447_add_faciliti    es_to_images_new")
         /var/www/roomhub/vendor/laravel/framework/src/Illuminate/Database/Migrations/Mig    rator.php:168

 2       Illuminate\Database\Migrations\Migrator::runUp("/var/www/roomhub/database/migrations/2018_05_26_085447_add_facilities_to_images_new.php")
  /var/www/roomhub/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:146

 Please use the argument -v to see more details.

这是移民文件

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddFacilitiesToImagesNewTable extends Migration
{
/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::table('images_new', function (Blueprint $table) {
        $table->string('facilities');
    });
}
/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('images_new', function (Blueprint $table) {
        $table->dropColumn('facilities');
    });
}
}

请问导致错误的是什么

1 个答案:

答案 0 :(得分:1)

按照这种思路,Class AddFacilitiesToImagesNew无法解决。

在错误回溯中,打印了一个从文件名确定类名的行。

$class = Str::studly(implode('_', array_slice(explode('_', $file), 4)));

严格来说,您的类必须在迁移文件中命名为AddFacilitiesToImagesNew

检查2018_05_26_085447_add_facilities_to_images_new.php中的迁移类是否正确命名为AddFacilitiesToImagesNew

编辑:还有一件事,迁移无需命名空间。 如果这个因为某种原因需要,请确保它已添加到您的作曲家并且您确实转储了自动加载文件。