[Bug]: data not be able to insert into the database
johnqiuwan opened this issue · 0 comments
johnqiuwan commented
What happened?
I have installed the latest version which is 1.0.13 . It seems not working for some reason (there is no any error message but just not working).
I have the sample data here.
the table migration file
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('course_orders', function (Blueprint $table) {
$table->id();
$table->string('code')->unique();
$table->tinyInteger('type')->default(1)->comment('1. online, 2. offline');
$table->foreignId('user_id')->index();
$table->decimal('amount', 10, 2);
$table->foreignId('payment_type_id')->index()->default(1)->comment('1. stripe, 2. credit card, 3. paypal');
$table->tinyInteger('order_status')->default(0)->comment('0. unpaid, 1. pending, 2. processing, 3. paid, 4. cancelled, 5. refunded, 6. failed, 8. completed');
$table->json('discounts')->nullable();
$table->tinyInteger('is_active')->default(1)->index();
$table->json('order_details')->nullable();
$table->json('order_items')->nullable();
$table->string('client_secret')->nullable();
$table->string('user_note')->nullable();
$table->string('payment_session_id')->nullable();
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('course_orders');
}
};
the factory file,
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\PaymentType;
use App\Models\User;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\CourseOrder>
*/
class CourseOrderFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$userId = 1;
return [
'code' => strtoupper(Str::random(10)),
'type' => $this->faker->randomElement([1, 2]), // 1 for online, 2 for offline
'user_id' => $userId, // Create a user dynamically
'amount' => $this->faker->randomFloat(2, 10, 500),
'payment_type_id' => $this->faker->randomElement([1, 2, 3]), // 1. stripe, 2. credit card, 3. paypal
'order_status' => $this->faker->randomElement([0, 1, 2, 3, 4, 5, 6, 8]),
'discounts' => $this->faker->optional()->randomElement([
['type' => 'percentage', 'value' => 10],
['type' => 'fixed', 'value' => 20],
]),
'is_active' => $this->faker->boolean(90),
'order_details' => [
'customer' => [
'name' => $this->faker->name,
'email' => $this->faker->safeEmail,
'phone' => $this->faker->phoneNumber,
],
'shipping_address' => [
'address_line_1' => $this->faker->streetAddress,
'city' => $this->faker->city,
'state' => $this->faker->state,
'postal_code' => $this->faker->postcode,
'country' => $this->faker->country,
],
'billing_address' => [
'address_line_1' => $this->faker->streetAddress,
'city' => $this->faker->city,
'state' => $this->faker->state,
'postal_code' => $this->faker->postcode,
'country' => $this->faker->country,
],
'payment_details' => [
'method' => 'stripe',
'transaction_id' => $this->faker->uuid,
'amount' => $this->faker->randomFloat(2, 10, 500),
],
],
'order_items' => [
[
'product_id' => 1,
'quantity' => 2,
'price' => $this->faker->randomFloat(2, 10, 100),
],
],
'user_note' => $this->faker->optional()->sentence,
'payment_session_id' => $this->faker->optional()->uuid,
];
}
}
when seeding the data, the data not be able to insert into the database. In addition, same file works when using sqlite.
How to reproduce the bug
seeding the data using the file
Package Version
1.0.13
PHP Version
8.2
Laravel Version
11.9
Which operating systems does with happen with?
macOS
Notes
I have no idea why it is not working. There is no error message in the log.,