I'm working on a project using Laravel framework's database component. This library includes a Database Abstraction Layer (DBAL) called “Capsule” and an Object Relational Mapping (ORM) library called “Eloquent”.
I want to update the extension already in DB, but I want also to insert a new "extension" if they don't exist. What is best way to do that?
My code so far:
try {
$updatedDomainsCount = Capsule::table('tbldomainpricing')
->where('extension', $tld)
->update(
[
'extension' => $tld,
'autoreg' => 'domenytv',
'grace_period' => '15',
'idprotection' => $idp,
'grace_period_fee' => $rea_price,
]
);
echo "Updated {$updatedDomainsCount} TLD: $tld</br>";
} catch (\Exception $e) {
echo "I couldn't update domains tld. {$e->getMessage()}";
}
Use Eloquent ORM method: updateOrCreate
, use to create new record or updated existing.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.