Chron
2 months ago
154
1
Laravel

Accessing models by using the pivot table

Posted 2 months ago by Chron

Is there a way to access the relationships of the pivot table?

For example:

Model1 -> Pivot -> model 2
		     |
		     V
		model 3

Is there a way to make it like this?

Model1::with('pivot.' ['model2, model3'])->get()

So the output should be like this:

all: [
	Model1 {
		...
		pivot{
			model2 {
				...
			},
			model3 {
				...
			}
		}
	},
]

Please sign in or create an account to participate in this conversation.