本文整理汇总了PHP中Builder::whereHas方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::whereHas方法的具体用法?PHP Builder::whereHas怎么用?PHP Builder::whereHas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Builder
的用法示例。
在下文中一共展示了Builder::whereHas方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scopeHasRole
/**
* Has role scope.
*
* @param Builder $query
* @param string $type
* @return Builder
*/
public function scopeHasRole($query, $type)
{
return $query->whereHas('roles', function ($query) use($type) {
$query->where('slug', $type);
});
}
示例2: setStringSearchQuery
/**
* Process STRING type of search
* @param Builder $query
* @param string $key
* @param array $values
*/
protected function setStringSearchQuery($query, $key, array $values)
{
$value = $values['values'][0];
switch ($values['operator']) {
case '~':
if (isset(static::$searchParams[$key]['relation'])) {
$relationKey = static::$searchParams[$key]['relation'][1];
$query->whereHas(static::$searchParams[$key]['relation'][0], function ($q) use($relationKey, $value) {
$q->where($relationKey, 'LIKE', "%{$value}%");
});
} else {
$query->where($key, 'LIKE', "%{$value}%");
}
break;
case '!~':
if (isset(static::$searchParams[$key]['relation'])) {
$relationKey = static::$searchParams[$key]['relation'][1];
$query->whereHas(static::$searchParams[$key]['relation'][0], function ($q) use($relationKey, $value) {
$q->where($relationKey, 'NOT LIKE', "%{$value}%");
});
} else {
$query->where($key, 'NOT LIKE', "%{$value}%");
}
break;
}
}
示例3: whereHasPostMeta
/**
* @param array $queries
* @param Builder $model
*
* @return Builder;
*/
public function whereHasPostMeta($queries, $model)
{
$queries = $this->sanitizeQuery($queries);
return $model->whereHas('postMeta', function ($q) use($queries) {
$this->metaQueryClause($queries, $q);
});
}