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?
Asked
Active
Viewed 2,106 times
3

nowilius
- 131
- 1
- 13
-
Yes it is using [laravel Model events](https://stackoverflow.com/q/29818317) !! – Maraboc Sep 30 '17 at 11:14
1 Answers
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