sql 在 laravel 5.6 中插入数组到字符串的转换错误
Array to string conversion error on sql insert in laravel 5.6
我试图在 laravel 5.6 上插入 order_items table 并出现以下错误
"Array to string conversion (SQL: insert into order_items
(title
, order_id
, quantity
, unit_price
, unit_booking_fee
) values (sector1, 129, 1, 1, 1))"
order_items table 架构
Schema::create('order_items', function ($table) {
$table->increments('id');
$table->string('title', 255);
$table->integer('quantity');
$table->decimal('unit_price', 13, 2);
$table->decimal('unit_booking_fee', 13, 2)->nullable();
$table->unsignedInteger('order_id');
$table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
$table->softDeletes();
});
我试过遵循这两个代码,但都给出了相同的错误
$orderItem = new OrderItem();
$orderItem->title = $attendee_details['ticket']['title'];
$orderItem->quantity = $attendee_details['qty'];
$orderItem->order_id = $order_id;
$orderItem->unit_price = $attendee_details['ticket']['price']; //0.15
$orderItem->unit_booking_fee = $attendee_details['ticket']['booking_fee'] + $attendee_details['ticket']['organiser_booking_fee']; //0.01
$orderItem->save();
OrderItem::create([
'title' => 'sector1',//$attendee_details['ticket']['title'],
'order_id' => $order_id,
'quantity' => $attendee_details['qty'],
'unit_price' => 1,
'unit_booking_fee' => 1
]);
我做错了什么?
解决了。
发现 $order_id 是一个数组
我试图在 laravel 5.6 上插入 order_items table 并出现以下错误
"Array to string conversion (SQL: insert into
order_items
(title
,order_id
,quantity
,unit_price
,unit_booking_fee
) values (sector1, 129, 1, 1, 1))"
order_items table 架构
Schema::create('order_items', function ($table) {
$table->increments('id');
$table->string('title', 255);
$table->integer('quantity');
$table->decimal('unit_price', 13, 2);
$table->decimal('unit_booking_fee', 13, 2)->nullable();
$table->unsignedInteger('order_id');
$table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
$table->softDeletes();
});
我试过遵循这两个代码,但都给出了相同的错误
$orderItem = new OrderItem();
$orderItem->title = $attendee_details['ticket']['title'];
$orderItem->quantity = $attendee_details['qty'];
$orderItem->order_id = $order_id;
$orderItem->unit_price = $attendee_details['ticket']['price']; //0.15
$orderItem->unit_booking_fee = $attendee_details['ticket']['booking_fee'] + $attendee_details['ticket']['organiser_booking_fee']; //0.01
$orderItem->save();
OrderItem::create([
'title' => 'sector1',//$attendee_details['ticket']['title'],
'order_id' => $order_id,
'quantity' => $attendee_details['qty'],
'unit_price' => 1,
'unit_booking_fee' => 1
]);
我做错了什么?
解决了。 发现 $order_id 是一个数组