jginorio
2 months ago
350
9
Laravel

How to sync a 3 model pivot table

Posted 2 months ago by jginorio

I want to sync a 3 model pivot table. This is how I can receive the data from my form.

$data = array(
	1 => ['user_id' => [0 => 5, 1 => 14]],
	2 => ['user_id' => [0 => 15]],
	3 => ['user_id' => [0 => 6]],
	4 => ['user_id' => [0 => 5]],
	6 => ['user_id' => [0 => 8, 1 => 3, 2 => 14]],
	7 => ['user_id' => [0 => 1]],
);

This is how I wish to store the data:

$order->crew()->sync($data);

This is how the database needs to look after the data is saved:

How database should look

The problem:

How can I do this?

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