本文整理匯總了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);
}
}