Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BernardK's avatar

save() versus create()

I'm sorry I'm new to Laravel and OOP, so these questions may sound rudimentary. I'm confused about save() or create() methods.

Does save() only works on objects and create() only works on arrays? How can I update a table using a method similar to create() method? (I tried using the create() method for updating a table and it is trying to insert into the table rather than updating a table.) If I have an array and want to update a table (using array), how do I do that? It looks like save() method only works on objects.

0 likes
5 replies
jekinney's avatar

Besure to take a gander at the source code. As @clay mentioned, there are differences. Sometimes minor sometimes major.

It's not really an oop thing as an eloquent and active record thing. Just FYI.

If you look at the source code for eloquent create it actually calls the save() method.

https://github.com/laravel/framework/blob/5.3/src/Illuminate/Database/Eloquent/Model.php#L557

While save()

https://github.com/laravel/framework/blob/5.3/src/Illuminate/Database/Eloquent/Model.php#L1448

Basically it's the same end result, insert data to the database, but the set up and how to use is slightly different.

ndiiorio's avatar

I've found a good usage of create() when using Model Observers, model observers have events you van call, creating(), created(), updating(), updated(), saving(), saved().

So creating and created are only called when create method is used. Updating and Updated when update method is used. And saving and saved when save method is used.

Documentation explains this too.

:D Hope to help and add some info to the replies.

Snapey's avatar
Snapey
Best Answer
Level 122

Eloquent only deals with objects (models) and performs database inserts and updates to persist those models.

Model::create(array);

is shorthand for the equivalent of

$model = new Model;
$model->fill(array);
$model->save();

new up an empty model(object) then fill it with your array of data, and finally save it.

If you want to update instead then first you have to find the record you are interested in, then update its values, and finally save save it;

$model = Model::findOrFail(1);
$model->fill(array)
$model->save();

Which, like the create method, there is a shortcut for;

Model::findOrFail(1)->update(array);
8 likes
BernardK's avatar

Thank you very very much Snapey, you made this subject so much more clearer to me! I really appreciate it. You can be one of the best programming tutor!

Please or to participate in this conversation.