Skip to content

Instantly share code, notes, and snippets.

@niczak
Created June 5, 2013 19:31
Show Gist options
  • Save niczak/5716548 to your computer and use it in GitHub Desktop.
Save niczak/5716548 to your computer and use it in GitHub Desktop.
UpSert Logic for Eloquent ORM
<?php
// search model for matching key
$record = FormDB::find('[email protected]');
if($record) {
// record exists, update data
$record->text = "Updated";
$record->save();
} else {
// no match found, insert data
$record = new FormDB;
$record->email = "[email protected]";
$record->text = "Inserted";
$record->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment