The following is the detailed error that I am getting. I am learning to make APIs with Laravel.
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'false' for column upwork_task.products.show at row 1 (SQL: insert into pro ducts (catalog_id, image, name, size, size_type, price, discounted_price, show, updated_at, created_at) values (1, https://via.placehol
der.com/640x480.png/00bbdd?text=clothes+quam, iPhone 14 Pro Max, 3191, liter, 3981, 2910, false, 2022-09-20 21:36:02, 2022-09-20 21:36:02))
My migration file is as follows
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('catalog_id');
$table->string('image');
$table->string('name');
$table->string('size');
$table->string('size_type');
$table->integer('price');
$table->integer('discounted_price')->nullable();
$table->boolean('show');
$table->timestamps();
});
My factory
public function definition()
{
$show = $this->faker->randomElement(['true', 'false']);
$size_type = $this->faker->randomElement(['ml', 'liter', 'gm', 'kg', 'oz', 'lb']);
$status = $this->faker->randomElement(['Y', 'N']); //Y means there is discount, N means there is none
$price = $this->faker->numberBetween($min = 10, $max = 9999);
return [
'catalog_id' => Catalog::factory(),
'image' => $this->faker->imageUrl($width = 640, $height = 480, 'clothes'),
'name' => 'iPhone 14 Pro Max',
'size' => $this->faker->numberBetween($min = 10, $max = 5000),
'size_type' => $size_type,
'price' => $price,
'discounted_price' => $status == 'Y' ? $this->faker->numberBetween($min = $price * 0.6, $max = $price * 0.9) : null,
'show' => $show,
];
}