V
V
Volodymyr2022-04-15 21:53:53
Laravel
Volodymyr, 2022-04-15 21:53:53

How to update a list of data using Relationships in Laravel?

Hello!

In Laravel, I create a list of data using hasMany :

$user = User::find($id);
        $user->phones()->createMany($myArray);


What method can be used to update that list in Laravel?
I look at the docks, there is no updateMany method there. It is necessary to add a new data list $myNewArray to phones(), at the same time, so that those elements that are in the new list and already in the table are not added to the table, and those remaining elements that are present in the table, but not in the new list, remove from the table, well, add all new elements to the table.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2022-04-15
@volodyalesha86

sync()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question