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('blah@blah.com');
if($record) {
// record exists, update data
$record->text = "Updated";
$record->save();
} else {
// no match found, insert data
$record = new FormDB;
$record->email = "blah@blah.com";
$record->text = "Inserted";
$record->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment