Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mknparreira/ef28ab7214073e81bb1dacc7613fdc96 to your computer and use it in GitHub Desktop.
Save mknparreira/ef28ab7214073e81bb1dacc7613fdc96 to your computer and use it in GitHub Desktop.
Laravel | check if updateOrCreate performed update
$tourist = Tourist::updateOrCreate([...]);

if(!$tourist->wasRecentlyCreated && $tourist->wasChanged()){
    // updateOrCreate performed an update
}

if(!$tourist->wasRecentlyCreated && !$tourist->wasChanged()){
    // updateOrCreate performed nothing, row did not change
}

if($tourist->wasRecentlyCreated){
   // updateOrCreate performed create
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment