本文整理匯總了PHP中Illuminate\Database\Query\Builder::join方法的典型用法代碼示例。如果您正苦於以下問題:PHP Builder::join方法的具體用法?PHP Builder::join怎麽用?PHP Builder::join使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::join方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: innerJoinOn
/**
* @param string $table table name
* @param string $key $table.key
* @param string|bool $fkey $this->table.key
* @return $this
*/
public function innerJoinOn($table, $key, $fkey = false)
{
$fkey = $fkey ?: $key;
$key = starts_with($key, $table . '.') ? $key : $table . '.' . $key;
$fkey = starts_with($key, $this->table . '.') ? $fkey : $this->table . '.' . $fkey;
$this->operator = $this->operator->join($table, $key, '=', $fkey);
return $this;
}
示例2: 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);
}
示例3: joinManyToManyRelation
protected function joinManyToManyRelation(Relations\BelongsToMany $relation, $type)
{
$pivotTable = $relation->getTable();
// $relation->getQualifiedParentKeyName() is protected
$parentKey = $relation->getParent()->getQualifiedKeyName();
$localKey = $relation->getOtherKey();
$this->query->join($pivotTable, $localKey, '=', $parentKey, $type);
$related = $relation->getRelated();
$foreignKey = $relation->getForeignKey();
$relatedTable = $related->getTable();
$relatedKey = $related->getQualifiedKeyName();
$this->query->join($relatedTable, $foreignKey, '=', $relatedKey, $type);
}
示例4: scopeJoinWithSelect
/**
* @param \Illuminate\Database\Query\Builder $query
* @param string $table join the table
* @param string $one joins first parameter
* @param string|array|null $operatorOrCollumns operator condition or collums list
* @param string $two joins two parameter
* @param string $type join type (left, right, '', etc)
* @param bool|false $where custom where condition
* @param array $collumns if you will not pass collumns, it will retreive the collumn listing. If you pass null
* it will not get any data from the model.
*
* @return \Illuminate\Database\Query\Builder
*/
public function scopeJoinWithSelect($query, $table, $one, $operatorOrCollumns, $two, $type = "left", $where = false, $collumns = array())
{
// if the operator collumns are in
if (is_array($operatorOrCollumns) || is_null($operatorOrCollumns)) {
$collumns = $operatorOrCollumns;
$operatorOrCollumns = "=";
}
if (!is_null($collumns)) {
// if there is no specific collumns, lets get all
if (empty($collumns)) {
$collumns = \Schema::getColumnListing($table);
}
// build the table values prefixed by the table to ensure unique values
foreach ($collumns as $related_column) {
$query->addSelect(new Expression("`{$table}`.`{$related_column}` AS `{$table}.{$related_column}`"));
}
}
return $query->join($table, $one, $operatorOrCollumns, $two, $type, $where);
}
示例5: join
/**
* Add a join clause to the query.
*
* @param string $table
* @param string $one
* @param string $operator
* @param string $two
* @param string $type
* @param bool $where
* @return $this
* @static
*/
public static function join($table, $one, $operator = null, $two = null, $type = 'inner', $where = false)
{
return \Illuminate\Database\Query\Builder::join($table, $one, $operator, $two, $type, $where);
}
示例6: addJoinQuery
/**
* Add joins to query builder
* @param \Illuminate\Database\Query\Builder $query object is by reference
*/
protected function addJoinQuery($query)
{
if (isset($this->join)) {
foreach ($this->join as $join) {
$query->join($join['table'], $join['one'], $join['operator'], $join['two']);
}
}
}
示例7: parseFilter
/**
* Parse the remaining filter params
*
* @param array $filterParams
* @return void
*/
protected function parseFilter($filterParams)
{
$supportedPostfixes = ['st' => '<', 'gt' => '>', 'min' => '>=', 'max' => '<=', 'lk' => 'LIKE', 'not-lk' => 'NOT LIKE', 'in' => 'IN', 'not-in' => 'NOT IN', 'not' => '!='];
$supportedPrefixesStr = implode('|', $supportedPostfixes);
$supportedPostfixesStr = implode('|', array_keys($supportedPostfixes));
foreach ($filterParams as $filterParamKey => $filterParamValue) {
$keyMatches = [];
//Matches every parameter with an optional prefix and/or postfix
//e.g. not-title-lk, title-lk, not-title, title
$keyRegex = '/^(?:(' . $supportedPrefixesStr . ')-)?(.*?)(?:-(' . $supportedPostfixesStr . ')|$)/';
preg_match($keyRegex, $filterParamKey, $keyMatches);
if (!isset($keyMatches[3])) {
if (strtolower(trim($filterParamValue)) == 'null') {
$comparator = 'NULL';
} else {
$comparator = '=';
}
} else {
if (strtolower(trim($filterParamValue)) == 'null') {
$comparator = 'NOT NULL';
} else {
$comparator = $supportedPostfixes[$keyMatches[3]];
}
}
$column = $keyMatches[2];
//resolve a relation->relation_column if we are using an eloquent builder.
if (strpos($column, '->') !== false && $this->isEloquentBuilder) {
$model = $this->builder->getModel();
//get the relation and the column in the relation
$relationComponents = explode('->', $column);
if (!method_exists($model, $relationComponents[0])) {
throw new ApiHandlerException('UnknownResourceRelation', ['relation' => $relationComponents[0]]);
}
$relation = call_user_func([$model, $relationComponents[0]]);
$relationColumn = $relationComponents[1];
$relationType = $this->getRelationType($relation);
if ($relationType === 'BelongsTo') {
$firstKey = $relation->getQualifiedForeignKey();
$secondKey = $relation->getQualifiedOtherKeyName();
} else {
if ($relationType === 'HasMany' || $relationType === 'HasOne') {
$firstKey = $relation->getQualifiedParentKeyName();
$secondKey = $relation->getForeignKey();
} else {
if ($relationType === 'BelongsToMany') {
$firstKey = $relation->getQualifiedParentKeyName();
$secondKey = $relation->getRelated()->getQualifiedKeyName();
}
}
}
//get the table to join to
$joinTable = $relation->getRelated()->getTable();
//do the join
$this->query->join($joinTable, $firstKey, '=', $secondKey);
//modify the $column name and continue parsing.
$column = $joinTable . '.' . $relationColumn;
$this->query->addSelect($model->getTable() . '.*');
}
//should we be using an eloquent builder, append the table name to every column to differentiate from joined columns.
if ($this->isEloquentBuilder) {
if (strpos($column, '.') === false) {
$column = $this->builder->getModel()->getTable() . '.' . $column;
}
}
if ($comparator == 'IN') {
$values = explode(',', $filterParamValue);
$this->query->whereIn($column, $values);
} else {
if ($comparator == 'NOT IN') {
$values = explode(',', $filterParamValue);
$this->query->whereNotIn($column, $values);
} else {
$values = explode('|', $filterParamValue);
if (count($values) > 1) {
$this->query->where(function ($query) use($column, $comparator, $values) {
foreach ($values as $value) {
if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
$value = preg_replace('/(^\\*|\\*$)/', '%', $value);
}
//Link the filters with AND of there is a "not" and with OR if there's none
if ($comparator == '!=' || $comparator == 'NOT LIKE') {
$query->where($column, $comparator, $value);
} else {
$query->orWhere($column, $comparator, $value);
}
}
});
} else {
$value = $values[0];
if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
$value = preg_replace('/(^\\*|\\*$)/', '%', $value);
}
if ($comparator == 'NULL' || $comparator == 'NOT NULL') {
$this->query->whereNull($column, 'and', $comparator == 'NOT NULL');
//.........這裏部分代碼省略.........
示例8: joinTableToQuery
/**
* Is used to join tables to main query using config file
* @param \Illuminate\Database\Query\Builder $query - Query Builder object - main query
* @param $join_table_name - table we need to join
* @param $current_table - table we join to
* @param $type - inner, left, right
* @return Illuminate\Database\Query\Builder $query - Query Builder object
*/
private static function joinTableToQuery($query, $join_table_name, $current_table, $type = 'inner')
{
$config_joins = Config::get('refinement.joins');
/* first we need to find join statement in configuration array */
$join_statement = array();
$join_statement_keys = array("{$current_table}|{$join_table_name}", "{$join_table_name}|{$current_table}");
foreach ($join_statement_keys as $join_statement_key) {
if (empty($config_joins[$join_statement_key])) {
continue;
}
$join_statement = $config_joins[$join_statement_key];
}
/* if there is no record in config array for this table, skip it */
if (empty($join_statement)) {
return $query;
}
return $query->join($join_table_name, $join_statement['left'], $join_statement['operand'], $join_statement['right'], $type);
}
示例9: scopeAllowedEbook
/**
* @param \Illuminate\Database\Query\Builder|static $query
*
* @return \Illuminate\Database\Query\Builder|static
*/
public function scopeAllowedEbook($query)
{
return $query->join('ebook_reader', "{$this->table}.user_id", '=', 'ebook_reader.reader_id')->join('ebooks', "ebooks.id", '=', 'ebook_reader.ebook_id')->addSelect(['ebook_reader.expires_at', 'ebook_reader.ebook_id', 'ebooks.title as ebook_title'])->orderBy('ebook_reader.created_at');
}