Hi @abdulbazith
you need to create pivot table like so
Schema::create('assessment_chapters', function (Blueprint $table) {
$table->unsignedBigInteger('assessment_id');
$table->unsignedBigInteger('chapter_id');
$table->foreign('assessment_id')
->references('id')
->on('assessments');
$table->foreign('chapter_id')
->references('id')
->on('chapter_details');
$table->primary(['assessment_id', 'chapter_id']);
});
and change your relations in Assessment model to
public function chapterdetails()
{
return $this->belongsToMany('App\ChapterDetails', 'assessment_chapters, 'assessment_id', 'chapter_id');
}
and in chapter details model to
public function assessmentdetails()
{
return $this->belongsToMany('App\AssessmentCreation', 'assessment_chapters, 'chapter_id', 'assessment_id');
}