public function audit(array $log)
    {
        try {
            $type     = $log['type'];
            $values   = $this->values();
            $authorId = array_get($log, 'author_id');
            if (is_null($authorId) && isset($values['owner_type'])) {
                $created = Logs::withoutGlobalScopes()->where([
                            'owner_type' => $values['owner_type'],
                            'type'       => 'created',
                            'owner_id'   => $values['owner_id']
                        ])->whereNotNull('author_id')->first();
                if (!is_null($created)) {
                    $authorId = $created->author_id;
                }
            }

            $logAuditing = array_merge([
                'author_id'      => $authorId,
                'old_value'      => $log['old_value'],
                'new_value'      => $log['new_value'],
                'related_data'   => $log['related_data'],
                'name'           => $this->resolveOperationName($type),
                'is_api_request' => is_api_request(),
                'type'           => $type], $values);

            $log             = new Logs($logAuditing);
            $log->created_at = (method_exists($this, 'createdAt')) ? $this->createdAt() : new DateTime();

            if (!$log->save()) {
                throw new Exception('Unable to save log entity.');
            }
        } catch (Exception $ex) {
            Log::emergency($ex);
            return false;
        }
        return true;
    }
public function audit(array $log)
    {
        try {
            $type     = $log['type'];
            $values   = $this->values();
            $authorId = array_get($log, 'author_id');
            if (is_null($authorId) && isset($values['owner_type'])) {
                $created = Logs::withoutGlobalScopes()->where([
                            'owner_type' => $values['owner_type'],
                            'type'       => 'created',
                            'owner_id'   => $values['owner_id']
                        ])->whereNotNull('author_id')->first();
                if (!is_null($created)) {
                    $authorId = $created->author_id;
                }
            }

            $logAuditing = array_merge([
                'author_id'      => $authorId,
                'old_value'      => $log['old_value'],
                'new_value'      => $log['new_value'],
                'related_data'   => $log['related_data'],
                'name'           => $this->resolveOperationName($type),
                'is_api_request' => is_api_request(),
                'type'           => $type], $values);

            $log             = new Logs($logAuditing);
            $log->created_at = (method_exists($this, 'createdAt')) ? $this->createdAt() : new DateTime();

            if (!$log->save()) {
                throw new Exception('Unable to save log entity.');
            }
        } catch (Exception $ex) {
            Log::emergency($ex);
            return false;
        }
        return true;
    }
public function audit ( array $ log ) { try { $ type = $ log [ 'type' ] ; $ values = $ this -> values ( ) ; $ authorId = array_get ( $ log , 'author_id' ) ; if ( is_null ( $ authorId ) && isset ( $ values [ 'owner_type' ] ) ) { $ created = Logs :: withoutGlobalScopes ( ) -> where ( [ 'owner_type' => $ values [ 'owner_type' ] , 'type' => 'created' , 'owner_id' => $ values [ 'owner_id' ] ] ) -> whereNotNull ( 'author_id' ) -> first ( ) ; if ( ! is_null ( $ created ) ) { $ authorId = $ created -> author_id ; } } $ logAuditing = array_merge ( [ 'author_id' => $ authorId , 'old_value' => $ log [ 'old_value' ] , 'new_value' => $ log [ 'new_value' ] , 'related_data' => $ log [ 'related_data' ] , 'name' => $ this -> resolveOperationName ( $ type ) , 'is_api_request' => is_api_request ( ) , 'type' => $ type ] , $ values ) ; $ log = new Logs ( $ logAuditing ) ; $ log -> created_at = ( method_exists ( $ this , 'createdAt' ) ) ? $ this -> createdAt ( ) : new DateTime ( ) ; if ( ! $ log -> save ( ) ) { throw new Exception ( 'Unable to save log entity.' ) ; } } catch ( Exception $ ex ) { Log :: emergency ( $ ex ) ; return false ; } return true ; }
Audit model.
Audit model .