本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::with方法的具体用法?PHP Builder::with怎么用?PHP Builder::with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::with方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: byPublicId
/**
* @param int $publicId
*
* @return Order
*/
public function byPublicId(int $publicId) : Order
{
/** @var Order $order */
$order = $this->orderResource->with(self::DEFAULT_RELATIONS)->where('id', '=', Order::privateId($publicId))->first();
if ($order instanceof Order) {
return $order;
}
return new Order();
}
示例2: withRelatedCriterion
public function withRelatedCriterion(QueryBuilder $query)
{
if ($this->related === null) {
throw new \RuntimeException('No relationships defined in the repository. Eloquent does ' . 'not support reading relationships from the Model. Related ' . 'models must be defined in the $related property of the ' . 'repository.');
}
return $query->with($this->related);
}
示例3: eagerLoad
/**
* Add relationships to the query builder to eager load
*
* @return $this
*/
protected function eagerLoad()
{
foreach ($this->with as $relation) {
$this->query->with($relation);
}
return $this;
}
示例4: table
/**
* Returns a new Issue table.
*
* @param Issue|Builder $issue
* @param array $with
* @param Closure $closure
*
* @return \Orchestra\Contracts\Html\Builder
*/
public function table($issue, array $with = ['users', 'labels'], Closure $closure = null)
{
$label = request('label');
// Filter issues with the specified request label.
$issue->with($with)->label($label)->latest();
return $this->table->of('issues', function (TableGrid $table) use($issue, $closure) {
if ($closure instanceof Closure) {
$table = call_user_func($closure, $table, $issue);
} else {
$table->with($issue)->paginate($this->perPage);
}
$table->sortable(['title', 'description', 'created_at']);
$table->searchable(['title', 'description']);
$table->column('status', function (Column $column) {
$column->label = '';
$column->value = function (Issue $issue) {
return $issue->present()->statusIcon();
};
$column->attributes(function () {
return ['width' => '30'];
});
});
$table->column('title', function (Column $column) {
return $this->tableTitle($column);
});
});
}
示例5: applyResourceOptions
/**
* Apply resource options to a query builder
* @param Builder $query
* @param array $options
* @return Builder
*/
protected function applyResourceOptions(Builder $query, array $options = [])
{
if (!empty($options)) {
extract($options);
if (isset($includes)) {
if (!is_array($includes)) {
throw new InvalidArgumentException('Includes should be an array.');
}
$query->with($includes);
}
if (isset($filter_groups)) {
$filterJoins = $this->applyFilterGroups($query, $filter_groups);
}
if (isset($sort)) {
if (!is_array($sort)) {
throw new InvalidArgumentException('Sort should be an array.');
}
if (!isset($filterJoins)) {
$filterJoins = [];
}
$sortingJoins = $this->applySorting($query, $sort, $filterJoins);
}
if (isset($limit)) {
$query->limit($limit);
}
if (isset($page)) {
$query->offset($page * $limit);
}
}
return $query;
}
示例6: scopeWithUserMessages
/**
* Returns all the registered users.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeWithUserMessages(Builder $query)
{
return $query->with(['user.messages' => function ($query) {
return $query->whereReceptorId(Auth::user()->id)->orderBy('created_at', 'asc');
}, 'user.receivedMessages' => function ($query) {
return $query->whereAuthorId(Auth::user()->id)->orderBy('created_at', 'asc');
}]);
}
示例7: 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;
}
示例8: 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();
}
示例9: 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();
}
示例10: eagerLoadRelations
/**
* @return $this
*/
protected function eagerLoadRelations()
{
if (isset($this->with)) {
foreach ($this->with as $relation) {
$this->model->with($relation);
}
}
return $this;
}
示例11: constraintBuilder
/**
* {@inheritdoc}
*/
public function constraintBuilder(EloquentBuilder $builder, array $options)
{
if ($relations = $this->eagerLoads(array_get($options, 'simple'))) {
$builder->with($relations);
}
$query = $builder->getQuery();
if ($value = array_get($options, 'order', $this->defaultOrder)) {
$this->order($query, $value);
}
}
示例12: 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;
}
示例13: scopeWithTranslation
/**
* This scope eager loads the translations for the default and the fallback locale only.
* We can use this as a shortcut to improve performance in our application.
*
* @param Builder $query
*/
public function scopeWithTranslation(Builder $query)
{
$query->with(['translations' => function ($query) {
$query->where(function ($query) {
$query->where($this->getTranslationsTable() . '.' . $this->getLocaleKey(), $this->locale());
if ($this->useFallback()) {
return $query->orWhere($this->getTranslationsTable() . '.' . $this->getLocaleKey(), $this->getFallbackLocale($this->locale()))->orWhere($this->getTranslationsTable() . '.' . $this->getLocaleKey(), $this->getFallbackLocale());
}
});
}]);
}
示例14: scopeWithEmbed
/**
* Otimiza as query do Eloquent adicionando
* Eager Loading do Eloquent
* @param string cidade,cidade.estado
* @return \Eloquent
*/
protected function scopeWithEmbed($embed = null)
{
$embed = is_null($embed) ? \Input::get('include') : $embed;
$requestedEmbeds = explode(',', $embed);
$possibleRelationships = (array) $this->model->relationships;
$eagerLoad = array_values(array_intersect($possibleRelationships, $requestedEmbeds));
if (!empty($eagerLoad)) {
\Log::info($eagerLoad);
$this->query->with($eagerLoad);
}
return $this;
}
示例15: 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();
}