entity instanceof PurchaseOrder){ $invitation = $this->entity->invitations()->where('vendor_contact_id', $this->contact_id)->first(); if(!$invitation) $invitation = $this->entity->invitations->first(); } else { $invitation = $this->entity->invitations()->where('client_contact_id', $this->contact_id)->first(); if(!$invitation) $invitation = $this->entity->invitations->first(); } if (! $invitation) { return; } $invitation->signature_base64 = $this->signature; $invitation->signature_date = now(); $invitation->signature_ip = $this->ip; $invitation->save(); } }