Created
June 5, 2013 19:31
-
-
Save niczak/5716548 to your computer and use it in GitHub Desktop.
UpSert Logic for Eloquent ORM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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