3

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?

nowilius
  • 131
  • 1
  • 13

1 Answers1

6

The updateOrCreate returns a model instance where you can check for recent creation

An example could be the following pseudo code

$model = Model::updateOrCreate($data);

if($model->wasRecentlyCreated) {
    // Do logic only when the model was created
}
Nicklas Kevin Frank
  • 6,079
  • 4
  • 38
  • 63