本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::newCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::newCollection方法的具体用法?PHP Model::newCollection怎么用?PHP Model::newCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::newCollection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newCollection
/**
* Use the custom collection that allows tapping.
*
* @param array $models An array of models to turn into a collection.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function newCollection(array $models = [])
{
if ($this->nukaCollections) {
return new Collection($models);
}
return parent::newCollection($models);
}
示例2: findMany
/**
* Find multiple models by their primary keys.
*
* @param array $ids
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findMany($ids, $columns = ['*'])
{
if (empty($ids)) {
return $this->model->newCollection();
}
$this->query->whereIn($this->model->getQualifiedKeyName(), $ids);
return $this->get($columns);
}
示例3: descendantsOf
/**
* Get descendants of specified node.
*
* @since 2.0
*
* @param mixed $id
* @param array $columns
*
* @return \Kalnoy\Nestedset\Collection
*/
public function descendantsOf($id, array $columns = array('*'))
{
try {
return $this->whereDescendantOf($id)->get($columns);
} catch (ModelNotFoundException $e) {
return $this->model->newCollection();
}
}
示例4: paginate
/**
* Paginate the given query.
*
* @param int $perPage
* @param array $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*
* @throws \InvalidArgumentException
*/
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
$page = $page ?: Paginator::resolveCurrentPage($pageName);
$perPage = $perPage ?: $this->model->getPerPage();
$query = $this->toBase();
$total = $query->getCountForPagination();
$results = $total ? $this->forPage($page, $perPage)->get($columns) : $this->model->newCollection();
return new LengthAwarePaginator($results, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
}
示例5: get
/**
* Execute the query as a "select" statement.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function get($columns = array('*'))
{
$models = $this->getModels($columns);
// If we actually found models we will also eager load any relationships that
// have been specified as needing to be eager loaded, which will solve the
// n+1 query issue for the developers to avoid running a lot of queries.
if (count($models) > 0) {
$models = $this->eagerLoadRelations($models);
}
return $this->model->newCollection($models);
}
示例6: delete
/**
* Delete a model by the following:
* $model itself when a model is given
* [$model[,...]] array or collection of models
* $id id of the model
* [id1[, id2, ...]] array of ids.
*
* @param mixed $model
* @return bool|int Boolean when model is deleted or the number of models deleted
*/
public function delete($model)
{
// First use-case, itself when a model is given
if ($model instanceof $this->model) {
return $model->delete();
}
// Second use-case, array or collection of models
$models = $model;
if (is_array($models) && head($models) instanceof $this->model) {
$models = $this->model->newCollection($models);
}
if ($models instanceof Collection) {
$model = $models->pluck('id');
// Pass ids to $model to be deleted below on third and fourth use-case
}
// Third and fourth use-case, id or array of ids
$ids = $model;
if (is_int($model)) {
$ids = [$ids];
}
if (!empty($ids)) {
return $this->model->destroy($ids);
}
}