public function save($entity, $silent = null)
    {
        try {
            if ($existing = $entity->getId()) {
                $creating = false;
            } else {
                $creating = true;
            }
        } catch (\Exception $e) {
            $creating = $existing = false;
        }

        if ($silent === null) {
            $event = new StorageEvent($entity, ['create' => $creating]);
            $this->event()->dispatch(StorageEvents::PRE_SAVE, $event);
        }

        if ($existing) {
            $response = $this->update($entity);
        } else {
            $response = $this->insert($entity);
        }

        if ($silent === null) {
            $this->event()->dispatch(StorageEvents::POST_SAVE, $event);
        }

        return $response;
    }
public function save($entity, $silent = null)
    {
        try {
            if ($existing = $entity->getId()) {
                $creating = false;
            } else {
                $creating = true;
            }
        } catch (\Exception $e) {
            $creating = $existing = false;
        }

        if ($silent === null) {
            $event = new StorageEvent($entity, ['create' => $creating]);
            $this->event()->dispatch(StorageEvents::PRE_SAVE, $event);
        }

        if ($existing) {
            $response = $this->update($entity);
        } else {
            $response = $this->insert($entity);
        }

        if ($silent === null) {
            $this->event()->dispatch(StorageEvents::POST_SAVE, $event);
        }

        return $response;
    }
public function save ( $ entity , $ silent = null ) { try { if ( $ existing = $ entity -> getId ( ) ) { $ creating = false ; } else { $ creating = true ; } } catch ( \ Exception $ e ) { $ creating = $ existing = false ; } if ( $ silent === null ) { $ event = new StorageEvent ( $ entity , [ 'create' => $ creating ] ) ; $ this -> event ( ) -> dispatch ( StorageEvents :: PRE_SAVE , $ event ) ; } if ( $ existing ) { $ response = $ this -> update ( $ entity ) ; } else { $ response = $ this -> insert ( $ entity ) ; } if ( $ silent === null ) { $ this -> event ( ) -> dispatch ( StorageEvents :: POST_SAVE , $ event ) ; } return $ response ; }
Saves a single object.

@param object $entity the entity to save
@param bool   $silent Suppress events

@return bool
Saves a single object .