App\Ninja\Repositories\VendorRepository::save PHP Method

save() public method

public save ( $data, $vendor = null )
    public function save($data, $vendor = null)
    {
        $publicId = isset($data['public_id']) ? $data['public_id'] : false;
        if ($vendor) {
            // do nothing
        } elseif (!$publicId || $publicId == '-1') {
            $vendor = Vendor::createNew();
        } else {
            $vendor = Vendor::scope($publicId)->with('vendor_contacts')->firstOrFail();
            if (Utils::isNinjaDev()) {
                \Log::warning('Entity not set in vendor repo save');
            }
        }
        if ($vendor->is_deleted) {
            return $vendor;
        }
        $vendor->fill($data);
        $vendor->save();
        $first = true;
        $vendorcontacts = isset($data['vendor_contact']) ? [$data['vendor_contact']] : $data['vendor_contacts'];
        $vendorcontactIds = [];
        foreach ($vendorcontacts as $vendorcontact) {
            $vendorcontact = $vendor->addVendorContact($vendorcontact, $first);
            $vendorcontactIds[] = $vendorcontact->public_id;
            $first = false;
        }
        if (!$vendor->wasRecentlyCreated) {
            foreach ($vendor->vendor_contacts as $contact) {
                if (!in_array($contact->public_id, $vendorcontactIds)) {
                    $contact->delete();
                }
            }
        }
        return $vendor;
    }

Usage Example

 /**
  * @param array $data
  * @param Vendor|null $vendor
  * @return mixed|null
  */
 public function save(array $data, Vendor $vendor = null)
 {
     if (Auth::user()->account->isNinjaAccount() && isset($data['plan'])) {
         $this->ninjaRepo->updatePlanDetails($data['public_id'], $data);
     }
     return $this->vendorRepo->save($data, $vendor);
 }
All Usage Examples Of App\Ninja\Repositories\VendorRepository::save