select($this->model->prefixColumn($columns)); if ($with) { if (is_string($with)) { $with = [$with]; } $merge = []; foreach ($with as $k => $v) { $rel = ( ! is_numeric($k) ? $k : $v); # with => merge if (is_string($rel) && stripos($rel, '+') === 0) { $rel = ltrim($rel, '+'); if (is_numeric($k)) { $merge[] = $rel; } else { $merge[$rel] = $v; } unset($with[$k]); continue; } # with => callback if (! is_numeric($k)) { $with[$k] = function ($q) use ($v) { if (is_string($v)) { $v = array_map('trim', explode(',', $v)); } $v[] = $q->getModel()->getQualifiedKeyName(); return $q->addSelect($v); }; } } if (! empty($merge)) { $query->merge(array_unique($merge)); $toArray = true; } if (! empty($with)) { $query->with($with); } } if (! empty($opts['tag'])) { $query->tag($opts['tag']); /** @see HasTags::tag */ } if (! empty($opts['cache'])) { if (is_numeric($opts['cache'])) { $query->cache($opts['cache']); /** @see HasCache::cache */ } } if ($this->model->usesLangs()) { if ($lang === true) { if (is_numeric($id)) { $data = $query->find($id); } else { $data = $query->where($id)->first(); } if (is_null($data)) { return ($toArray ? [] : $data); } if ($this->model->usesLangsTable()) { $data->langLoad(); /** @see Langs::langLoad */ } elseif ($this->model->usesLangsColumns()) { $data->langDataTransform(); /** @see LangsColumns::langDataTransform */ } return ($toArray ? $data->toArray() : $data); } else { $query->lang($lang); /** @see LangsBase::scopeLang */ } } if (is_numeric($id)) { $data = $query->find($id); } else { $data = $query->where($id)->first(); } return ($toArray ? ($data !== null ? $data->toArray() : []) : $data); # todo if (is_null($data)) { if ($toArray) { return []; } else { throw new ModelRecordNotFoundException(); } } return ($toArray ? $data->toArray() : $data); } /** * Execute the query as a "select" statement. * * @param array $columns * @return \Illuminate\Database\Eloquent\Collection|static[] */ public function get($columns = ['*']) { # Ensure columns set before any global scopes applied if ($this->model->usesLangs()) { # Columns should be prefixed + lang tables joined $this->query->columns = $columns = $this->model->joinLangs($this->query, $columns); } $this->model->prefixWhereColumns($this->query); $collection = parent::get($columns); if ($this->model->usesLangsColumnsJson()) { $collection = $this->model->jsonLangsMapCollectionGet($collection); } return $collection; } /** * Get an array with the values of a given column. * * @param string $column * @param string|null $key * @return \Illuminate\Support\Collection */ public function pluck($column, $key = null) { # Ensure columns set before any global scopes applied if ($this->model->usesLangs() && $this->model->isLangColumn($column)) { # Columns should be prefixed + lang tables joined list($column, $key) = $this->model->joinLangs($this->query, [$column, $key]); } $this->model->prefixWhereColumns($this->query); $collection = parent::pluck($column, $key); if ($this->model->usesLangsColumnsJson()) { $collection = $this->model->jsonLangsMapCollectionPluck($collection, $column); } return $collection; } }