Find many by IDs.

@param array $ids

@return \Illuminate\Database\Eloquent\Collection
428956
public function findManyByIds(array $ids)
    {
        $models = $this->model->whereIn($this->model->getKeyName(), array_unique($ids))
            ->get();

        return $models;
    }
604117
public function findAllNew($ids = [])
    {
        $query = $model = $this->makeModel()->where('broadcasted', 0);
        if (!empty($ids)) {
            $values = array_values($ids);
            $query->whereNotIn('id', $values);
        }
        return $query->get();
    }
192783
public function findByIds(array $ids): array
    {
        $spec = $this->createSpecification()->where(['id' => $ids]);

        return $this->findAll($spec);
    }
589236
public static function scopesFor(array $ids)
    {
        return collect($ids)->map(function ($id) {
            if (isset(static::$scopes[$id])) {
                return new Scope($id, static::$scopes[$id]);
            }

            return;
        })->filter()->values()->all();
    }
377831
public function deleteByIdArray(array $ids)
    {
        $data['ids'] = $ids;

        $deleteResult = $this->getRequest()->request(
            'DELETE',
            $this->getRequestUrl('inputs'),
            $data
        );

        return $deleteResult['status'];
    }
402053
public function findById(array $ids)
    {
        $ids = $this->idsToMongo($ids);

        $documents = array();
        $remaining = array();
        foreach ($ids as $id) {
            if ($this->identityMap->has($id)) {
                $documents[(string) $id] = $this->identityMap->get($id);
            } else {
                $remaining[] = $id;
            }
        }

        if (count($documents) == count($ids)) {
            return $documents;
        }

        return array_merge(
            $documents,
            $this->createQuery(array('_id' => array('$in' => $remaining)))->all()
        );
    }
1371749
public function findByLevels($levels = 1, $ids = array())
    {
        $query = $this->createQueryBuilder('c');

        if ($levels > 0) {
            $selects = ['c'];
            for ($i = 1; $i <= $levels; ++$i) {
                $selects[] = 'c'.$i;
            }

            $query->select($selects);

            for ($i = 1; $i <= $levels; ++$i) {
                $previous = ($i - 1 == 0) ? '' : ($i - 1);
                $query->leftJoin('c'.$previous.'.children', 'c'.$i, 'WITH', 'c'.$i.'.active = :active AND c'.$i.'.showInNavigation = :show');
            }
        }

        if ($ids) {
            $query->andWhere('c.id IN (:ids)')->setParameter('ids', $ids);
        } else {
            $query->andWhere('c.parent IS NULL');
        }

        $query->andWhere('c.active = :active')->setParameter('active', true);
        $query->andWhere('c.layout = :layout')->setParameter('layout', false);
        $query->andWhere('c.showInNavigation = :show')->setParameter('show', true);

        return $query->getQuery()->getResult();
    }
992819
public static function findByIds($ids, $throwException = true)
    {
        $ids = array_unique($ids);
        $ids = array_map('intval', $ids);
        $ids2find = array_diff($ids, array_keys(static::$identityMap));
        if (count($ids2find) > 0) {
            Property::find()->where(['in', 'id', $ids2find])->all();
        }

        return array_reduce(
            $ids,
            function ($carry, $id) use ($throwException) {
                if (isset(static::$identityMap[$id])) {
                    $carry[$id] = static::$identityMap[$id];
                } elseif ($throwException) {
                    throw new \RuntimeException("Property $id not found");
                }
                return $carry;
            },
            []
        );
    }
1114140
public static function findOrFail($ids, $columns = ['*'])
    {
        $result = self::find($ids, $columns);

        if (!is_null($result)) {
            return $result;
        }

        throw (new ModelNotFoundException)->setModel(
            __CLASS__, $ids
        );
    }
683903
public function getValues(array $ids)
    {
        $values = [];
        foreach ($ids as $id => $default) {
            if (is_int($id)) {
                $id = $default;
            }
            $values[$id] = $this->getValue($id, $default);
        }

        return $values;
    }
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;
    }
785164
protected function gatherIds(array $array, array $ids = array())
    {
        foreach ($array as $item) {
            $ids[] = $item['id'];
            if (isset($item['__children']) && count($item['__children'])) {
                $ids = $this->gatherIds($item['__children'], $ids);
            }
        }

        return $ids;
    }
951063
public function findMany($id, $columns = ['*'])
    {
        if (empty($id)) {
            return new EntityCollection();
        }

        $this->query->whereIn($this->entityMap->getKeyName(), $id);

        return $this->get($columns);
    }
1238654
public function getReadRequest($ids)
    {
        $searchRequest = $this->getSearchRequest([$this->primaryKey => $ids], count($ids));
        
        return new StorageDataRequest(
            [$searchRequest, $this->primaryKey],
            function (StorageDataRequest $searchRequest, $primaryKey) {
                $searchRequest->send();
                
                return [$searchRequest, $primaryKey];
            },
            function (StorageDataRequest $searchRequest, $primaryKey) {
                if ($searchRequest->fetch()) {
                    return array_column($searchRequest->getResult(), null, $primaryKey);
                }
                
                return $searchRequest->getResult();
            }
        );
    }
73068
public static function find(...$ids)
    {
        if(!isset($ids[0]))
        {
            return null;
        }
        $query = static::query();
        if(is_callable($ids[0]))
        {
            // 回调传入条件
            call_user_func($ids[0], $query);
        }
        else
        {
            // 传主键值
            if(is_array($ids[0]))
            {
                // 键值数组where条件
                foreach($ids[0] as $k => $v)
                {
                    $query->where($k, '=', $v);
                }
            }
            else
            {
                // 主键值
                $id = ModelManager::getId(static::__getRealClassName());
                if(is_string($id))
                {
                    $id = [$id];
                }
                foreach($id as $i => $idName)
                {
                    if(!isset($ids[$i]))
                    {
                        break;
                    }
                    $query->where($idName, '=', $ids[$i]);
                }
            }
        }

        // 查找前
        Event::trigger(static::__getRealClassName() . ':' . ModelEvents::BEFORE_FIND, [
            'ids'   => $ids,
            'query' => $query,
        ], null, \Imi\Model\Event\Param\BeforeFindEventParam::class);

        $result = $query->select()->get();

        // 查找后
        Event::trigger(static::__getRealClassName() . ':' . ModelEvents::AFTER_FIND, [
            'ids'   => $ids,
            'model' => &$result,
        ], null, \Imi\Model\Event\Param\AfterFindEventParam::class);

        return $result;
    }
1226335
public function newQueryForRestoration($ids)
    {
        return is_array($ids)
                ? $this->newQueryWithoutScopes()->whereIn($this->getQualifiedKeyName(), $ids)
                : $this->newQueryWithoutScopes()->whereKey($ids);
    }
633842
public function findMany($ids, $columns = ['*'])
    {
        if (empty($ids)) {
            return $this->model->newCollection();
        }

        return $this->whereKey($ids)->get($columns);
    }