src/Models/ApiObject.php
protected function processAttachments($data)
    {
        $idList = [];
        foreach ($data as $attachmentData) {
            $idList[] = $attachmentData['id'];

            // Find a matching attachment or create it
            $attachment = Attachment::get()->filter(['HailID' => $attachmentData['id']])->first();

            if (!$attachment) {
                $attachment = new Attachment();
            }
            $attachment->OrganisationID = $this->OrganisationID;
            $attachment->HailOrgID = $this->HailOrgID;
            $attachment->HailOrgName = $this->HailOrgName;

            // Update the Hail Attachments
            $attachment->importHailData($attachmentData);

            if (!$this->Attachments()->byID($attachment->ID)) {
                $this->Attachments()->add($attachment);
            }
        }

        // Remove old attachments that are currently assigned to this article,
        // but have not been returned this time around
        if ($idList) {
            $this->Attachments()->exclude('HailID', $idList)->removeAll();
        } else {
            // If there's no attachements, just remove everything.
            $this->Attachments()->removeAll();
        }
    }
protected function processAttachments($data)
    {
        $idList = [];
        foreach ($data as $attachmentData) {
            $idList[] = $attachmentData['id'];

            // Find a matching attachment or create it
            $attachment = Attachment::get()->filter(['HailID' => $attachmentData['id']])->first();

            if (!$attachment) {
                $attachment = new Attachment();
            }
            $attachment->OrganisationID = $this->OrganisationID;
            $attachment->HailOrgID = $this->HailOrgID;
            $attachment->HailOrgName = $this->HailOrgName;

            // Update the Hail Attachments
            $attachment->importHailData($attachmentData);

            if (!$this->Attachments()->byID($attachment->ID)) {
                $this->Attachments()->add($attachment);
            }
        }

        // Remove old attachments that are currently assigned to this article,
        // but have not been returned this time around
        if ($idList) {
            $this->Attachments()->exclude('HailID', $idList)->removeAll();
        } else {
            // If there's no attachements, just remove everything.
            $this->Attachments()->removeAll();
        }
    }
protected function processAttachments ( $ data ) { $ idList = [ ] ; foreach ( $ data as $ attachmentData ) { $ idList [ ] = $ attachmentData [ 'id' ] ; // Find a matching attachment or create it $ attachment = Attachment :: get ( ) -> filter ( [ 'HailID' => $ attachmentData [ 'id' ] ] ) -> first ( ) ; if ( ! $ attachment ) { $ attachment = new Attachment ( ) ; } $ attachment -> OrganisationID = $ this -> OrganisationID ; $ attachment -> HailOrgID = $ this -> HailOrgID ; $ attachment -> HailOrgName = $ this -> HailOrgName ; // Update the Hail Attachments $ attachment -> importHailData ( $ attachmentData ) ; if ( ! $ this -> Attachments ( ) -> byID ( $ attachment -> ID ) ) { $ this -> Attachments ( ) -> add ( $ attachment ) ; } } // Remove old attachments that are currently assigned to this article, // but have not been returned this time around if ( $ idList ) { $ this -> Attachments ( ) -> exclude ( 'HailID' , $ idList ) -> removeAll ( ) ; } else { // If there's no attachements, just remove everything. $ this -> Attachments ( ) -> removeAll ( ) ; } }
Go through the attachments and assign them to this object.

@param array $data JSON data from Hail
Go through the attachments and assign them to this object .