public function scopeGetEntity($query, $entityId, $entityType, $fieldId)
    {
        $entities = $query->where('entity_id', $entityId)
                        ->where('entity_type', $entityType)
                        ->where('field_id', $fieldId)->get();
        if ($entities->count()) {
            $object = $entities[0];
        } else {
            $object = new self();
        }

        return $object;
    }
public function scopeGetEntity($query, $entityId, $entityType, $fieldId)
    {
        $entities = $query->where('entity_id', $entityId)
                        ->where('entity_type', $entityType)
                        ->where('field_id', $fieldId)->get();
        if ($entities->count()) {
            $object = $entities[0];
        } else {
            $object = new self();
        }

        return $object;
    }
public function scopeGetEntity ( $ query , $ entityId , $ entityType , $ fieldId ) { $ entities = $ query -> where ( 'entity_id' , $ entityId ) -> where ( 'entity_type' , $ entityType ) -> where ( 'field_id' , $ fieldId ) -> get ( ) ; if ( $ entities -> count ( ) ) { $ object = $ entities [ 0 ] ; } else { $ object = new self ( ) ; } return $ object ; }
Find entities by entityID,type and fieldId.

@param $query
@param $entityId
@param $entityType
@param $fieldId

@return Entity
Find entities by entityID type and fieldId .