K
K
kfedor2017-03-27 14:49:05
Laravel
kfedor, 2017-03-27 14:49:05

What's the difference between save() and associate() methods in Laravel?

What's the difference between save() and associate() methods in Laravel?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor, 2017-03-27
@kfedor

save saves the model, associate is used to save the BelongsTo connection and is called not on the model itself, but on the result of the relation method.

Z
Zamir Yusupov, 2017-03-27
@id717891

"When updating belongsTo relationships, you can use the associate() method. It will set the foreign key on the associated model." I think associate just makes a selection, and save is already a save procedure in the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question