Save record on pivot table with many to many relation

Submitted by Mahmoud_Zalt - 8 years ago

Add the attributes on the second parameter of the attach function.

$chapter->courses()->attach($course->id, ['chapter_order_number' => $index]);