Support the ongoing development of →
Input Eloquent
Last updated 1 year ago.

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


Sign in to participate in this thread!


Your banner here too?

0w3n86 0w3n86 Joined 8 Nov 2015


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

Your logo here?

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

© 2024 - All rights reserved.