lyonio's avatar

Laravel eloquent updateOrCreate(), do something only if create?

I use in my laravel 5.5 app Model::updateOrCreate(), it works, but by 1 parameter I wish to do something only if entry is creating and not updating model, is this possible?

0 likes
2 replies
sutherland's avatar

There is a wasRecentlyCreated property on models you can check. For example:

$model = Model::updateOrCreate(
    // ...
);

if($model->wasRecentlyCreated){
    // Do this only if it was recently created
}
2 likes

Please or to participate in this conversation.