Saving with multiple relationships

Posted 2 years ago by techn0guy

Hello I'm trying to accomplish the following:

A product display has a foreign key for a line item. A line item has a foreign key for a color, size, product display, and store. I've already created and stored a product display and I'm trying to now create the line item. However I keep running into the error:

Argument 1 passed to Illuminate\Database\Grammar::columnize() must be of the type array, integer given

What am I doing incorrectly? I have three hasMany() relationships on my LineItem model called size(), color(), product_display() and store()

$lineitem = new LineItem;
$lineitem->title = 'test title';
$lineitem->sku = 'testsku';
$lineitem->size()->associate(Size::firstOrFail($size_key));
$lineitem->color()->associate(Color::firstOrFail($color_key));
$lineitem->stores()->associate($this->store);
$lineitem->product_display()->associate($product_display);
$product_display->lineItems()->save($lineitem);

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

Reply to

Use Markdown with GitHub-flavored code blocks.