在Migrator.php第418行:Class' Table'运行迁移时未找到错误

时间:2018-01-27 18:27:29

标签: php mysql laravel laravel-5.5

我想在我的项目中使用laravel-payment-gateway laravel包。

它有两个迁移文件,我将它们添加到laravel项目中的迁移文件夹中。包括:

create_gateway_transactions_table.php

namespace NextpayPayment\Gateway;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
use NextpayPayment\Gateway\ConstGateway;

class CreateGatewayTransactionsTables extends Migration
{
    function getTable()
    {
        return config('gateway.table', 'nextpay_gateway_transactions');
    }

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->getTable(), function (Blueprint $table) {
            $table->engine = "innoDB";
            $table->unsignedBigInteger('id', true);
            $table->enum('gateway', [
                ConstGateway::NEXTPAY,
            ]);
            $table->integer('status')->default(ConstGateway::TRANSACTION_PENDING);
            $table->integer('state')->default(ConstGateway::TRANSACTION_PENDING);
            $table->decimal('price', 15, 2);
            $table->string('trans_id', 50)->nullable();
            $table->string('card_number', 50)->nullable();
            $table->string('ip', 20)->nullable();
            $table->timestamp('payment_date')->nullable();
            $table->unsignedBigInteger('id_commodity');
            $table->nullableTimestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop($this->getTable());
    }
}

这样的 alter_id_in_transactions_table.php

<?php

use Illuminate\Support\Facades\DB;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Migrations\Migration;

class AlterIdInTransactionsTables extends Migration
{

    function getTable()
    {
        return config('gateway.table', 'nextpay_gateway_transactions');
    }

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        try {       
//          DB::statement("update `" . $this->getTable() . "` set `payment_date`=null WHERE  `payment_date`=0;");
//          DB::statement("ALTER TABLE `" . $this->getTable() . "` CHANGE `id` `id` BIGINT UNSIGNED NOT NULL;");


            Schema::create('nextpay_gateway_transactions', function (Blueprint $table) {
                $table->increments('id');
                $table->string('name');
                $table->string('airline');
                $table->timestamps();
            });

        } catch (Exception $e) {

        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
//      DB::statement("ALTER TABLE `" . $this->getTable() . "` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL;");
        Schema::drop($this->getTable());
    }
}

但是在运行php artisan migrate之后我收到了这个错误:

In Migrator.php line 418:

  Class 'Table' not found

什么是问题,如何解决?

2 个答案:

答案 0 :(得分:4)

尝试通过在终端/ cmd中运行以下命令来手动创建迁移:

php artisan make:migration create_gateway_transactions_tables
php artisan make:migration alter_id_in_transactions_table

然后将代码复制粘贴到新创建的迁移中。也尝试运行:

composer dump-autoload

希望这有帮助。

答案 1 :(得分:3)

迁移文件名必须与类名相同。此外,您需要为名称添加日期和时间。因此,将文件名更改为:

2018_01_15_100000_create_gateway_transactions_tables.php
2018_01_15_100001_alter_id_in_transactions_tables.php

确保其他迁移也可以并运行composer du。然后使用迁移。

您可以在Tinker中自行测试:

$file = '2018_01_15_100000_create_gateway_transactions_tables.php';
$class = \Illuminate\Support\Str::studly(implode('_', array_slice(explode('_', $file), 4)));

第二行来自给出错误的方法。