Get the related models out of their Ids.

@param  array  $ids
@return \Illuminate\Database\Eloquent\Collection
198403
public function modelsFromIds($ids)
    {
        // We need a Model in order to save this relationship so we try
        // to whereIn the given id(s) through the related model.
        return $this->related->whereIn($this->related->getKeyName(), (array) $ids)->get();
    }
592174
public function getCover($ids)
    {
        if (empty($ids) || $ids === '{}' || $ids === '[]') return null;

        $ids = $this->parseGalleryIds($ids);

        $id = current($ids);

        $imageModel = $this->getImageModelName();

        return call_user_func_array([$imageModel, 'find'], [$id]);
    }
1261020
public function selectByIds(array $ids = array())
    {
        if (empty($ids)) {
            return array();
        }

        $ids = array_map('intval', $ids);

        $sql = $this->getSelectQueryByIds($ids);

        $resultSet = $this->db->fetchAll($sql);

        return $this->implementVOs($resultSet);
    }
507280
public function findByIds(array $ids)
    {
        $entities = [];

        for ($i = 0; $i < count($this->registries); $i++) {
            /** @var RegistryInterface $registry */
            $registry = $this->registries[ $i ];
            $found = $registry->findByKeys($ids);
            $entities = array_merge($entities, $found);

            $this->updateRegistries($found, $i - 1);

            if (count($entities) === count($ids)) {
                break;
            }
        }

        return $entities;
    }
618062
public function detach($ids = [])
    {
        if ($ids instanceof EntityCollection) {
            $ids = (array) $ids->modelKeys();
        }

        $query = $this->newPivotQuery();

        // If associated IDs were passed to the method we will only delete those
        // associations, otherwise all of the association ties will be broken.
        // We'll return the numbers of affected rows when we do the deletes.
        $ids = (array) $ids;

        if (count($ids) > 0) {
            $query->whereIn($this->otherKey, (array) $ids);
        }

        // Once we have all of the conditions set on the statement, we are ready
        // to run the delete on the pivot table. Then, if the touch parameter
        // is true, we will go ahead and touch all related models to sync.
        return $query->delete();
    }
1088152
private function getImages(array $ids)
    {
        if (empty($ids)) {
            return [];
        }

        $qb = $this->getImageRepository()->createQueryBuilder('o');

        $images = $qb
            ->where($qb->expr()->in('o.id', $ids))
            ->orderBy('o.position')
            ->getQuery()
            ->getResult();

        if (count($images) !== count($ids)) {
            throw $this->createNotFoundException('Unable to find one or more images.');
        }

        return $images;
    }
216675
public function findByIds($ids)
    {
        $query = $this->createQueryBuilder('m')
            ->where('m.id IN (:ids)')
            ->andWhere('m.status = :status')
            ->setParameters(array(
                'ids' => $ids,
                'status' => 1,
            ))
            ->getQuery()
        ;

        return $query->getResult();
    }
443664
public function itemsGet($ids) {
		if ((!is_array($ids)) || (empty($ids))) {
			BLog::addToLog('[BItems.' . $this->tableName . '] itemsGet() $ids empty=' . var_export($ids, true) . ')', LL_ERROR);
			return array();
		}
		if (DEBUG_LOG_BITEMS) {
			BLog::addToLog('[BItems.' . $this->tableName . '] itemsGet(' . implode(',', $ids) . ')');
		}
		$items = array();
		//-------------------------------------------------
		//Trying to get items from internal cache
		//-------------------------------------------------
		$ids_c = array(); //IDs as integer
		$ids_k = array(); //IDs as external cache key
		foreach ($ids as $id) {
			$idd = is_array($id) ? implode(':', $id) : $id;
			if (isset($this->cacheItems[$idd])) {
				$items[$idd] = $this->cacheItems[$idd];
			} else {
				if (!empty($idd)) {
					$items[$idd] = NULL;
					$ids_c[$idd] = $id;
					$ids_k[$idd] = $this->tableName . ':itemid:' . $idd;
				}
			}
		}
		if (empty($ids_c)) {
			return $items;
		}

		//-------------------------------------------------
		//Trying to get left items from external cache
		//-------------------------------------------------
		$cache = BFactory::getCache();
		if (!empty($cache)) {
			$ids_m = array();
			$ids_q = array();
			$items_c = $cache->mget($ids_k);
			foreach ($ids_c as $id) {
				$idd = is_array($id) ? implode(':', $id) : $id;
				$key = $this->tableName . ':itemid:' . $idd;
				if ((isset($items_c[$key])) && (!empty($items_c[$key]))) {
					$classname = $this->itemClassName;
					$items[$idd] = new $classname();
					$items[$idd]->load($items_c[$key]);
					$this->cacheItems[$idd] = $items[$idd];
				} else {
					array_push($ids_m, $id);
					array_push($ids_q, $id);
				}
			}
		} else {
			$ids_m = $ids_c;
			$ids_q = $ids_c;
		}
		if (empty($ids_m)) {
			return $items;
		}
		//-------------------------------------------------
		// Trying to get left items from database
		//-------------------------------------------------
		$db = BFactory::getDBO();
		if (empty($db)) {
			return $items;
		}
		if (is_array($this->primaryKeyName)) {
			$whi = array();
			foreach ($ids_q as $id) {
				$s = array();
				foreach ($id as $idk => $idv) {
					$s[] = '(`' . $idk . '`=' . $db->escapeString($idv) . ')';
				}
				$whi[] = '(' . implode(' AND ', $s) . ')';
			}
			$wh = implode(' OR ', $whi);
			$qr = 'SELECT * from `' . $this->tableName . '` WHERE (' . $wh . ')';
		} else {
			$qr = 'SELECT * from `' . $this->tableName . '` WHERE (`' . $this->primaryKeyName . '` in (' . implode(',', $ids_q) . '))';
		}
		$q = $db->Query($qr);
		if (empty($q)) {
			BLog::addToLog('[items]: itemsGet(): Could not execute query! MySQL error: ' . $db->lasterror(), LL_ERROR);
			return $items;
		}
		$tocache = array();
		$item_obj = array();
		while ($l = $db->fetch($q)) {
			if (is_array($this->primaryKeyName)) {
				$id = array();
				foreach ($this->primaryKeyName as $pk) {
					$id[$pk] = $l[$pk];
				}
				$idd = implode(':', $id);
				$item_obj[$idd] = $l;
			} else {
				$idd = (int)$l[$this->primaryKeyName];
				$item_obj[$idd] = $l;
			}
			foreach ($this->linkedTables as $tbl) {
				$item_obj[$idd][$tbl['field']] = array();
			}
		}
		//-------------------------------------------------
		// Loading data from external tables...
		//-------------------------------------------------
		if (DEBUG_LOG_BITEMS) {
			BLog::addToLog('[BItems.' . $this->tableName . '] itemsGet() Loading data from external tables...');
		}
		foreach ($this->linkedTables as $tbl) {
			$wh = array();
			$wh[] = '(`' . $tbl['extkey'] . '` in (' . implode(',', $ids_q) . '))';
			if (!empty($tbl['filter'])) {
				$wh[] = $tbl['filter'];
			}
			$qrl = 'SELECT * from `' . $tbl['name'] . '` WHERE (' . implode(' AND ', $wh) . ')';
			$ql = $db->Query($qrl);
			if (empty($ql)) {
				BLog::addToLog('[items]: itemsGet(): Could not execute external tables query! MySQL error: ' . $db->lasterror(), LL_ERROR);
				return false;
			}
			$datal = array();
			while ($ll = $db->fetch($ql)) {
				$itemid = (int)$ll[$tbl['extkey']];
				$item_obj[$itemid][$tbl['field']][] = $ll;
			}
		}
		//-------------------------------------------------
		// Creating item object...
		//-------------------------------------------------
		if (DEBUG_LOG_BITEMS) {
			BLog::addToLog('[BItems.' . $this->tableName . '] itemsGet() Creating item objects...');
		}
		foreach ($item_obj as $k => $l) {
			$classname = $this->itemClassName;
			if (!class_exists($classname)) {
				$msg = 'Class "' . $classname . '" does not exist!';
				BLog::addToLog($msg, LL_ERROR);
				die($msg);
			}
			$items[$k] = new $classname();
			$items[$k]->load($l);
			$this->cacheItems[$k] = $items[$k];
			if (CACHE_TYPE) {
				$tocache[$this->tableName . ':itemid:' . $k] = $l;
			}
		}
		//-------------------------------------------------
		// Cache storing, if necessary.
		//-------------------------------------------------
		if ((!empty($cache)) && (count($tocache) != 0)) {
			$cache->mset($tocache, $this->cacheTime);//1 hour
		}
		if (DEBUG_LOG_BITEMS) {
			BLog::addToLog('[BItems.' . $this->tableName . '] itemsGet() All done! Returning items.');
		}
		return $items;
	}
497676
protected function detachUsingCustomClass($ids)
    {
        $results = 0;

        foreach ($this->parseIds($ids) as $id) {
            $results += $this->newPivot([
                $this->foreignPivotKey => $this->parent->{$this->parentKey},
                $this->relatedPivotKey => $id,
            ], true)->delete();
        }

        return $results;
    }
1203578
protected static function idsToMongoIds($ids)
    {
        if (!is_array($ids)) {
            // comma delimited list of ids
            $ids = array_map('trim', explode(',', trim($ids, ',')));
        }

        foreach ($ids as &$id) {
            $id = static::idToMongoId($id);
        }

        return $ids;
    }
686555
private function getItemById(array $ids)
    {
        $ids = array_map('intval', $ids);

        try {
            $stmtResult = $this->neo4jClient->run('MATCH (n) WHERE ID(n) IN {ids} RETURN n', ['ids' => $ids]);
        } catch (\Exception $e) {
            return [];
        }

        $result = [];

        if (!$stmtResult->size()) {
            return $result;
        }

        foreach ($stmtResult->records() as $record) {
            $result[] = $record->get('n');
        }

        return $result;
    }
1128309
public function findMany($ids, $columns = array('*'))
    {
        if (empty($ids)) {
            return $this->model->newCollection();
        }

        $keyName = $this->model->getQualifiedKeyName();

        $this->query->whereIn($keyName, $ids);

        return $this->get($columns);
    }
411733
public function several(array $ids)
    {
        $results = [];

        foreach ($ids as $cacheId) {
            if ($this->cache->test($cacheId)) {
                $results[$cacheId] = $this->cache->load($cacheId);
            }

        }

        return $results;
    }
514469
public function ids($ids)
    {
        $ids = is_array($ids) ? $ids : [$ids];

        $query = new IdsQuery($ids);

        $this->append($query);

        return $this;
    }
974910
public static function deleteByIds($ids, array $params = [])
    {
        if (!is_array($ids)) {
            $ids = explode(",", $ids);
        }

        $m = new static;
        $pk = $m->getPrimaryKey();
        $records = [];
        foreach ($ids as $id) {
            $records[] = [$pk => $id];
        }

        return static::bulkDelete($records, $params);
    }
703647
protected function load(array $ids = array())
    {
        $idsNotFound = array_filter($ids);

        $output = array();

        $stores = $this->stores;

        foreach ($this->stores as $storeName => $store) {
            if (!empty($idsNotFound)) {
                $objects = $store->load($idsNotFound);

                $loadedKeys = array_keys($objects);
                $remainingKeys = array_values(array_diff($idsNotFound, $loadedKeys));
                $idsNotFound = $remainingKeys;
                $output = $output + $objects;

                if (!empty($objects) && $store == $this->primaryStore) {
                    foreach ($stores as $storeName2 => $store2) {
                        if ($storeName2 !== $storeName) {
                            $ret = $store2->saveMulti($objects);
                        }
                    }
                }
            }
        }


        return $output;
    }
886311
protected function getEagerModelKeys(array $models)
    {
        // First we need to gather all of the keys from the parent models so we know what
        // to query for via the eager loading query. We will add them to an array then
        // execute a "where in" statement to gather up all of those related records.
        $keys = collect($models)->map(function ($model) {
            return $model->{$this->foreignKey};
        })->filter()->all();

        // If there are no keys that were not null we will just return an array with either
        // null or 0 in (depending on if incrementing keys are in use) so the query wont
        // fail plus returns zero results, which should be what the developer expects.
        if (count($keys) === 0) {
            return [$this->relationHasIncrementingId() ? 0 : null];
        }

        return array_values(array_unique($keys));
    }