使用方法updateOrCreate
,有没有办法知道记录是否被更新或创建?
UPDATE:我需要使用这个功能来返回201
,对于创建的记录,或者204
更新记录。
谢谢。
Since 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
您可以使用以下命令检查最近是否创建了记录:$instance->wasRecentlyCreated
https://github.com/laravel/framework/blob/5.3/src/Illuminate/Database/Eloquent/Model.php#L1593 https://github.com/laravel/framework/blob/5.3/src/Illuminate/Database/Eloquent/Model.php#L1593
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)