/** * Generates an account from the contact's company field, if that field has a value */ private static function generateAccount(Contacts $contact) { if (isset($contact->company)) { $account = new Accounts(); $account->name = $contact->company; if ($account->save()) { $account->refresh(); $contact->company = $account->nameId; $contact->update(); } } }