movepixels
2 weeks ago
199
6
Laravel

Polymorphic Help

Posted 2 weeks ago by movepixels

Never did this before and reading the docs is not working.

Idea is I want to have a Model OrderItem with table "order_items" that will hold all the items for an Invoice. Since the items can come from Subscription, Product, Upgrade models.

So to test out I have OrderItem.php:

public function line_item()
  {
    return $this->morphTo();
  }

Upgrade.php:

public function OrderItem()
  {
    return $this->morphMany('App\Models\Billing\Orders\OrderItem', 'line_item');
  }

But when trying to add an item to a new order like so just to test:

$newOrder->OrderItems()->save($upgrade);

I get errors. Its trying tto update the Ugrades table.

Unknown column 'order_id' in 'field list' (SQL: update `upgrades` set `updated_at` = 2019-10-05 20:25:29, `order_id` = 0 where `id` = 1)

Why is it trying to even touch Upgrade table?

Anyone once know where I am going wrong.

Please sign in or create an account to participate in this conversation.