本文整理匯總了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);
});
}