/** * @param $table * @param $key $table.key * @param bool $fkey $this->table.key * @return $this */ public function leftJoinOn($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->leftJoin($table, $key, '=', $fkey); return $this; }
/** * Add a left join to the query. * * @param string $table * @param string $first * @param string $operator * @param string $second * @return \Illuminate\Database\Query\Builder|static * @static */ public static function leftJoin($table, $first, $operator = null, $second = null) { return \Illuminate\Database\Query\Builder::leftJoin($table, $first, $operator, $second); }
/** * @param \Illuminate\Database\Query\Builder $query * @return \Illuminate\Database\Query\Builder */ public function scopeWithAuthor($query) { return $query->leftJoin('users', 'users.id', '=', "{$this->table}.user_id")->addSelect("users.username as author"); }
/** * Load thông tin user * * @param \Illuminate\Database\Query\Builder $query * * @return \Illuminate\Database\Query\Builder|static */ public function scopeWithUser($query) { $query->leftJoin('users', "{$this->table}.user_id", '=', "users.id")->addSelect('users.name as user_name', 'users.username as user_username'); return $query; }
/** * $query 에 join 된 쿼리를 리턴 * * @param Builder $query query builder * @return Builder */ public function joinRevision(Builder $query) { $config = $this->config; $tableName = $query->from; $table = $this->handler->getConfigHandler()->getRevisionTableName($config); $query->leftJoin($table, function (JoinClause $join) use($tableName, $table, $config) { $join->on(sprintf('%s.%s', $tableName, $config->get('joinColumnName')), '=', sprintf('%s.dynamicFieldTargetId', $table))->on(sprintf('%s.revisionId', $tableName), '=', sprintf('%s.revisionId', $table)); }); return $query; }