Support the ongoing development of Laravel.io →
Input Eloquent
Last updated 2 years ago.
0
Solution

Answer from laracasts:

attach does not work like that.

Let me take out two lines of code:

$candidate->qualification()->attach($qualification_id); $candidate->qualification()->attach($cert_number);

You are trying to add the $cert_number as a qualification_id, which is why it fails. When you do this, how is Laravel supposed to know that the second line ($cert_number) is an extra pivot column? It doesn't. You have two lines of code that are exactly the same so you can't expect Laravel to know that the second line should do something different.

When you want to insert extra data into other pivot columns, you need to pass them as an array in the second argument. Something like this:

$candidate->qualification()->attach($qualification_id, ['cert_number' => $cert_number]);

0

Sign in to participate in this thread!

Eventy

Your banner here too?

0w3n86 0w3n86 Joined 8 Nov 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.