本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::select方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::select方法的具体用法?PHP Model::select怎么用?PHP Model::select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::select方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getByKey
/**
* Get local by key .
*
* @param $key
* @param $locale
* @param null $group
* @return mixed
*/
public function getByKey($key, $locale, $group = null)
{
$query = $this->source->select('languages.slug as locale', 'translations.*')->join('languages', 'languages.id', '=', 'translations.language_id')->where('languages.slug', $locale)->whereKey($key);
if ($group) {
$query->where('group', $group);
}
return $query->first();
}
示例2: getByCriteriaQuery
/**
* Generates the query builder object required for the get query requests.
*
* @param array $params
* @return mixed
*/
private function getByCriteriaQuery($params)
{
$query = $this->model->select(['*']);
foreach ($params as $key => $value) {
$query->where($key, '=', $value);
}
return $query;
}
示例3: buildQuery
private function buildQuery()
{
$this->query = app(get_class($this->model));
if (!empty($this->fields)) {
$this->query = $this->query->select($this->fields);
}
if (!empty($this->relations)) {
$this->relations = array_unique($this->relations);
$this->query = $this->query->with($this->relations);
}
if (!empty($this->per_page)) {
$this->query = $this->query->take($this->per_page);
}
if (count($this->conditions)) {
foreach ($this->conditions as $condition) {
$this->query = $this->query->where($condition['column'], $condition['operator'], $condition['value'], $condition['boolean']);
}
}
}
示例4: buildBaseQuery
/**
* create a base eloquent search
*
* @return null
*/
public function buildBaseQuery()
{
$this->query = $this->model->select();
}
示例5: scopeToSubQuery
/**
* @param EloquentBuilder|QueryBuilder|Model $query
* @param string $key
* @param bool $returnExpression
*
* @return string
*/
public function scopeToSubQuery($query, $key, $returnExpression = false)
{
$index = 0;
$bindings = array();
if (!Str::contains($key, '.')) {
/** @var Model|BetterEloquentTrait $model */
$model = $query->getModel();
$key = $model->getField($key);
}
$sql = $query->select(array($key))->toSql();
foreach ($query->getBindings() as $binding) {
$bindings[] = is_array($binding) ? array_merge($bindings, $binding) : $binding;
}
while (Str::contains($sql, '?')) {
$sql = $this->replaceFirst('?', $bindings[$index++], $sql);
}
$sql = "({$sql})";
return $returnExpression ? new Expression($sql) : $sql;
}