[英]Laravel 5.4 - 'updateOrCreate' method. Check If record was 'updated' or 'created'
Using the method updateOrCreate
, is there a way to know which if a record was updated or created? 使用updateOrCreate
方法,有没有办法知道记录是更新或创建的?
UPDATE: I need to use this feature to return 201
, for created record, or 204
for updated record. 更新:我需要使用此功能返回201
,创建记录,或204
更新记录。
Thank you. 谢谢。
Since updateOrCreate
returns the model instance. 由于updateOrCreate
返回模型实例。 https://github.com/laravel/framework/blob/5.4/src/Illuminate/Database/Eloquent/Builder.php#L374 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 您可以使用以下命令检查最近创建的记录: $instance->wasRecentlyCreated
https://github.com/laravel/framework/blob/5.3/src/Illuminate/Database/Eloquent/Model.php#L1593
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.