本文整理汇总了PHP中Illuminate\Database\Query\Builder::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::with方法的具体用法?PHP Builder::with怎么用?PHP Builder::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::with方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: iterateAll
/**
* @return Generator|Product[]
*/
public function iterateAll() : Generator
{
/** @var Product $product */
foreach ($this->productResource->with('images')->cursor() as $product) {
if (!$product->relationLoaded('images')) {
$product->load('images');
}
(yield $product);
}
}
示例2: getAll
/**
* Retrive all notifications, not read
* in first.
* You can also limit the number of
* Notifications if you don't, it will get all
*
* @param $to_id
* @param $entity
* @param null $limit
* @param bool $paginate
* @param string $orderDate
* @return mixed
*/
public function getAll($to_id, $entity, $limit = null, $paginate = false, $orderDate = 'desc')
{
$result = $this->notification->with('body', 'from')->wherePolymorphic($to_id, $entity)->orderBy('read', 'ASC')->orderBy('created_at', $orderDate);
// if the limit is set
if (!is_null($limit)) {
$result->limit($limit);
}
return $result->get();
}
示例3: with
/**
* Load relations
*
* @param array|string $relations
* @return $this
*/
public function with($relations)
{
/**
* Save to conditons.
*/
$this->addCondition('with', $relations);
$this->model = $this->model->with($relations);
return $this;
}
示例4: getAll
/**
* Retrive all notifications, not read
* in first.
* You can also limit the number of
* Notifications if you don't, it will get all
*
* @param $to_id
* @param $entity
* @param null $limit
* @param int|null $paginate
* @param string $orderDate
* @param Closure $filterScope
* @return mixed
*/
public function getAll($to_id, $entity, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null)
{
$query = $this->notification->with('body', 'from')->wherePolymorphic($to_id, $entity)->orderBy('read', 'ASC')->orderBy('created_at', $orderDate);
$query = $this->applyFilter($filterScope, $query);
if (is_int(intval($paginate)) && $paginate) {
return $query->paginate($limit);
}
return $query->get();
}
示例5: scopeWithRevisionsWithoutData
/**
* @param Builder|\Illuminate\Database\Query\Builder $builder
* @param null $columns
*
* @return mixed
*/
public function scopeWithRevisionsWithoutData($builder, $columns = null)
{
$columns = $columns ?: ['id', 'event', 'revisionable_type', 'revisionable_id', 'user_id', 'created_at', 'updated_at'];
$builder->with(['revisions' => function ($q) use($columns) {
/** @var Builder|\Illuminate\Database\Query\Builder $q */
$q->select($columns);
$q->with('user');
}]);
return $builder;
}
示例6: getStack
/**
* Retrive all notifications, in a stack.
* You can also limit the number of
* Notifications if you don't, it will get all.
*
* @param $stackId
* @param null $limit
* @param int|null $paginate
* @param string $orderDate
* @param Closure $filterScope
* @return mixed
*/
public function getStack($stackId, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null)
{
$query = $this->notification->with('body', 'from', 'to')->byStack($stackId)->orderBy('read', 'ASC')->orderBy('created_at', $orderDate);
if ($limit && !$paginate) {
$query->limit($limit);
}
$query = $this->applyFilter($filterScope, $query);
if (is_int(intval($paginate)) && $paginate) {
return $query->paginate($limit);
}
return $query->get();
}
示例7: buildQuery
private function buildQuery()
{
$this->query = app(get_class($this->model));
if (!empty($this->fields)) {
$this->query = $this->query->select($this->fields);
}
if (!empty($this->relations)) {
$this->relations = array_unique($this->relations);
$this->query = $this->query->with($this->relations);
}
if (!empty($this->per_page)) {
$this->query = $this->query->take($this->per_page);
}
if (count($this->conditions)) {
foreach ($this->conditions as $condition) {
$this->query = $this->query->where($condition['column'], $condition['operator'], $condition['value'], $condition['boolean']);
}
}
}
示例8: search
public function search($field, $word, $with = [], $perPage = 15)
{
$word = strtolower($word);
$constraint = config('database.default') === 'mysql' ? 'LIKE' : 'ILIKE';
return $this->query->with($with)->where($field, $constraint, '%' . $word . '%')->paginate($perPage);
}
示例9: buildIncludes
/**
* @param Builder|QueryBuilder $queryBuilder
* @param array $includes
*/
protected function buildIncludes($queryBuilder, array $includes)
{
$builtIncludes = [];
foreach ($includes as $includeName => $include) {
// Support for array includes, example: ['user', 'post']
// If it's a single dimension array the key will be numeric
$includeName = is_numeric($includeName) ? $include : $includeName;
if (empty($include['where']) && empty($include['fields']) && empty($include['order'])) {
$builtIncludes[] = $includeName;
continue;
}
$builtIncludes[$includeName] = function ($query) use($include) {
if (isset($include['where'])) {
$this->buildWheres($query, $include['where']);
}
if (isset($include['fields'])) {
$this->buildFields($query, $include['fields']);
}
if (isset($include['order'])) {
$this->buildOrderBy($query, $include['order']);
}
};
}
$queryBuilder->with($builtIncludes);
}