Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DavidBuchukuri's avatar

how to implement many to many relationship between 3 tables?

I have candidates skills and criterias table. Each candidate can have many skills and criterias, and candidate has score for each criteria. for example:

{
		name: 'peter'
		skills: [
		  {
			  name: 'laravel',
			  criterias: [
				{
					name: 'eloquent',
					score: 45
				},
				{
					name: 'service providers',
					score: 37
				}
			 ]
			},
				{
					name: 'vue js',
					criterias: [
						{
							name: 'pinia',
							score: 23
						},
						{
							name: 'vuex',
							score: 15
						}
					]
				}
		]

}

What's the good way to implement that with eloquent?

0 likes
1 reply
SilenceBringer's avatar

@davidbuchukuri If you need a pivot table between 3 tables - I recommend to not think about it as pivot table and make separated model instead (like CandidateSkillCriteria)

Because laravel do not support pivots between 3 tables and you'll not be able to eager load all related data

That's it

1 like

Please or to participate in this conversation.