我想在我的项目中使用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
什么是问题,如何解决?
答案 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)));
第二行来自给出错误的方法。