本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::join方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::join方法的具体用法?PHP Builder::join怎么用?PHP Builder::join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::join方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle the command.
*
* @param RoleRepositoryInterface $roles
*/
public function handle(RoleRepositoryInterface $roles)
{
if (!$this->query->getQuery()->joins && ($permission = array_get($this->fieldType->getConfig(), 'permission'))) {
$accessible = $roles->findByPermission($permission);
if (!$accessible->isEmpty()) {
$this->query->join('users_users_roles', 'users_users_roles.entry_id', '=', 'users_users.id')->whereIn('users_users_roles.related_id', $accessible->lists('id'));
}
}
}
示例2: apply
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function apply(Builder $builder, Model $model)
{
if (isset($model->required) && $model->required) {
$builder->join('tmp_documents', function ($join) {
$join->on('tmp_documents.id', '=', 'persons_documents.document_id')->where('is_required', '=', true)->wherenull('persons_documents.deleted_at');
});
} else {
$builder->join('tmp_documents', function ($join) {
$join->on('tmp_documents.id', '=', 'persons_documents.document_id')->where('is_required', '=', false)->wherenull('persons_documents.deleted_at');
});
}
}
示例3: apply
/**
* Apply the scope to a given Eloquent query builder.
* @param Builder $builder
* @param Model $model
*/
public function apply(Builder $builder, Model $model)
{
$builder->join('product_translations', function ($join) {
$join->on('products.id', '=', 'product_translations.product_id')->where('product_translations.locale', '=', app()->getLocale())->where('product_translations.published', '=', 1);
});
$builder->select(['products.*']);
}
示例4: build
public function build(Builder $query)
{
$tagIds = array_map(function (TagInterface $tag) {
return $tag->getId();
}, $this->tags);
return $query->join('pages_tags', 'pages.id', '=', 'pages_tags.page_id')->whereIn('pages_tags.tag_id', $tagIds)->groupBy('pages.id')->having(DB::raw('count(distinct pages_tags.tag_id)'), '=', count($tagIds));
}
示例5: build
public function build(Builder $query)
{
$page = $this->page;
return $query->join('pages_tags', 'tags.id', '=', 'pages_tags.tag_id')->join('pages', 'pages_tags.page_id', '=', 'pages.id')->where(function ($query) use($page) {
$query->where('pages.id', '=', $page->getId())->orWhere('pages.parent_id', '=', $page->getId());
})->groupBy('tags.id')->orderBy('tags.name', 'asc');
}
示例6: onQuerying
/**
* Fired just before querying
* for table entries.
*
* @param Builder $query
*/
public function onQuerying(Builder $query)
{
$uploaded = $this->getUploaded();
if ($fieldType = $this->getFieldType()) {
/*
* If we have the entry available then
* we can determine saved sort order.
*/
$entry = $fieldType->getEntry();
$table = $fieldType->getPivotTableName();
if ($entry->getId() && !$uploaded) {
$query->join($table, $table . '.file_id', '=', 'files_files.id');
$query->where($table . '.entry_id', $entry->getId());
$query->orderBy($table . '.sort_order', 'ASC');
} else {
$query->whereIn('id', $uploaded ?: [0]);
}
} else {
/*
* If all we have is ID then just use that.
* The JS / UI will be handling the sort
* order at this time.
*/
$query->whereIn('id', $uploaded ?: [0]);
}
}
示例7: scopeSiblings
/**
* Get the siblings of the specified entry ID
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int|array $entryId
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeSiblings(Builder $query, $entryId)
{
$entryId = is_array($entryId) ? $entryId : array($entryId);
$connection = $query->getQuery()->getConnection();
$tablePrefix = $connection->getTablePrefix();
return $query->join('relationships', 'relationships.child_id', '=', 'channel_titles.entry_id')->join($connection->raw("`{$tablePrefix}relationships` AS `{$tablePrefix}relationships_2`"), 'relationships_2.parent_id', '=', 'relationships.parent_id')->addSelect('*')->addSelect('relationships_2.child_id AS sibling_id')->whereIn('relationships_2.child_id', $entryId)->orderBy('relationships.order', 'asc')->groupBy('relationships_2.child_id')->groupBy('relationships.field_id')->groupBy('channel_titles.entry_id');
}
示例8: apply
/**
* @param Builder $builder
* @param Model $model
*/
public function apply(Builder $builder, Model $model)
{
$builder->join('post_translations', function ($join) {
$join->on('posts.id', '=', 'post_translations.post_id')->where('post_translations.locale', '=', app()->getLocale())->where('post_translations.publish_at', '<', Carbon::now()->format('Y-m-d H:i:s'));
});
$builder->select(['posts.*']);
}
示例9: apply
/**
* Apply the scope to a given Eloquent query builder.
* @param Builder $builder
* @param Model $model
*/
public function apply(Builder $builder, Model $model)
{
$builder->join('uris', function ($join) use($model) {
$join->where('uris.owner_type', '=', get_class($model));
$join->on('uris.owner_id', '=', $model->getTable() . '.' . $model->getKeyName());
})->select([$model->getTable() . '.*', 'uris.uri']);
}
示例10: apply
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function apply(Builder $builder, Model $model)
{
$builder->join($model->getVersionTable(), function ($join) use($model) {
$join->on($model->getQualifiedKeyName(), '=', $model->getQualifiedVersionKeyName());
$join->on($model->getQualifiedVersionColumn(), '=', $model->getQualifiedLatestVersionColumn());
});
$this->extend($builder);
}
示例11: build
public function build(Builder $query)
{
foreach ($this->tags as $i => $tag) {
$alias = "tag-{$i}";
$query->join("pages_tags as {$alias}", 'pages.id', '=', "{$alias}.page_id")->where("{$alias}.tag_id", '=', $tag->getId());
}
return $query;
}
示例12: handle
/**
* Handle the command.
*
* @param RoleRepositoryInterface $roles
*/
public function handle(RoleRepositoryInterface $roles)
{
if ($role = array_get($this->fieldType->getConfig(), 'role')) {
if (is_numeric($role)) {
$role = $roles->find($role);
}
if (is_string($role)) {
$role = $roles->findBySlug($role);
}
if ($role) {
// The role exists so join and limit results to that role's ID.
$this->query->join('users_users_roles', 'users_users_roles.entry_id', '=', 'users_users.id')->where('users_users_roles.related_id', $role->getId());
} else {
// The role doesn't exist so don't return anything.
$this->query->join('users_users_roles', 'users_users_roles.entry_id', '=', 'users_users.id')->where('users_users_roles.related_id', false);
}
}
}
示例13: generateJoin
/**
* @param string $table
* @param array $ons
* @param array $conditions
* @param string $joinType
*
* @throws \InvalidArgumentException
*/
private function generateJoin($table, $ons, $conditions = array(), $joinType = '')
{
$this->query->join($table, function (JoinClause $q) use($conditions, $ons) {
foreach ($ons as $on) {
$q->on($on[0], array_key_exists(2, $on) ? $on[2] : '=', $on[1]);
}
$this->generateJoinConstraints($q, $conditions);
}, null, null, $joinType === '' ? $this->joinType : $joinType);
}
示例14: build
public function build(Builder $query)
{
$query->join('assets_tags', 'assets_tags.asset_id', '=', 'assets.id');
if (is_array($this->tags)) {
$query->whereIn('assets_tags.tag', $this->tags)->groupBy('tag')->having(DB::raw('count(distinct tag)'), '=', count($this->tags));
} else {
$query->where('assets_tags.tag', '=', $this->tags);
}
return $query;
}
示例15: modifyQuery
public function modifyQuery(Builder $query)
{
$query->join('users', 'users.id', '=', 'team_users.user_id');
if ($this->get('team_id')) {
$query->where('team_id', $this->get('team_id'));
}
if ($this->get('user_id')) {
$query->where('user_id', $this->get('user_id'));
}
return $query;
}