4

I'm trying to insert into order_items table on laravel 5.6 and getting following error

"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

    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();
    });

I've tried following both code and both give same error

        $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
        ]);

What am i doing wrong?

1 Answer 1

2

Solved it. Found that the $order_id was an array

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.