Laravel 5.4 - 'updateOrCreate' method. Check If record was 'updated' or 'created'

后端 未结 1 1913
有刺的猬
有刺的猬 2021-02-14 23:52

Using the method updateOrCreate, is there a way to know which if a record was updated or created?

UPDATE: I need to use this feature to ret

相关标签:
1条回答
  • 2021-02-15 00:32

    Since updateOrCreate returns the model instance. https://github.com/laravel/framework/blob/5.4/src/Illuminate/Database/Eloquent/Builder.php#L374

    You can check that a record was recently created using: $instance->wasRecentlyCreated https://github.com/laravel/framework/blob/5.3/src/Illuminate/Database/Eloquent/Model.php#L1593

    0 讨论(0)
提交回复
热议问题