本文整理汇总了PHP中RainLab\User\Models\User::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP User::whereIn方法的具体用法?PHP User::whereIn怎么用?PHP User::whereIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RainLab\User\Models\User
的用法示例。
在下文中一共展示了User::whereIn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scopeSearch
/**
* Search topics and posts.
*
* @param QueryBuilder $query
* @param string $search
* @param bool $includePosts
* @return QueryBuilder
*/
public function scopeSearch($query, $search, $includePosts = True)
{
$search = trim($search);
if (strlen($search)) {
$parsed = Search::parseQuery($search, ['topic', 'post'], ['topic' => 'topic', 'post' => 'post', 'author' => 'author', 'by' => 'author']);
// Search authors?
$authors = !empty($parsed['author']) ? User::whereIn(DB::raw('LOWER(username)'), $parsed['author'])->lists('id') : [];
$query->where(function ($query) use($parsed, $authors, $includePosts) {
if (!empty($parsed['topic'])) {
$query->searchWhere(implode(' ', $parsed['topic']), 'name');
if ($authors && empty($parsed['post'])) {
$query->whereIn('author_id', $authors);
}
}
if ($includePosts && !empty($parsed['post'])) {
$query->orWhereHas('posts', function ($query) use($parsed, $authors) {
$query->searchWhere(implode(' ', $parsed['post']), 'post');
if ($authors) {
$query->whereIn('author_id', $authors);
}
});
}
});
}
return $query;
}
示例2: scopeSearch
/**
* Search topics and posts.
*
* @param QueryBuilder $query
* @param string $search
* @return QueryBuilder
*/
public function scopeSearch($query, $search)
{
$parsed = Search::parseQuery($search, ['post'], ['post' => 'post', 'author' => 'author', 'by' => 'author']);
// Search authors
$authors = !empty($parsed['author']) ? User::whereIn(DB::raw('LOWER(username)'), $parsed['author'])->lists('id') : [];
if ($authors) {
$query->whereIn('author_id', $authors);
}
// Search posts
if (!empty($parsed['post'])) {
$query->searchWhere(implode(' ', $parsed['post']), 'post');
}
return $query;
}