DevMaster's avatar

Return of Model::create() versus new Model()

Hello LaraV.I.P.s

Just wondering if the return types of Model::create() and new Model() are supposed to be the same? Or do they differ?

I ask because I would expect them to be the same, but I'm experiencing different behaviour when using one versus the other (especially in the save() and associate() Eloquent methods).

Best regards, Dev Master

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

new Model will be an instance in memory until it is saved; while Model::create() persists the record in the database immediately. Many operations relying on foreign keys will not work until the former is saved.

1 like

Please or to participate in this conversation.