我已经在数据库查询上建立了一个过滤器,现在
我想让它更舒适.
目标是使其具有动态性,这意味着
用户可以选择任意组合.
public function filter(FilterList $request)
{
$view = view('profile.browse.list');
$search = $request->get('filter');
$filter = [
'male' => Profile::male(),
'female' => Profile::female(),
'10' => Profile::man(),
'11' => Profile::women(),
'12' => Profile::couple(),
'15' => Profile::domina(),
'20' => Profile::affaire(),
'21' => Profile::cybersex(),
'22' => Profile::marriage(),
'23' => Profile::flirt(),
];
return $view->with([
'List' => $filter[$search]->unmoderated()->paginate(15)->appends(['filter' => $search]),
]);
}
我知道我的解决方案并不是很好的解决方案.
我已将查询范围保存在$filter数组中,
无法添加第二个或想要的范围
$users = User :: popular()-> women()-> orderBy(‘created_at’)-> get();
有任何暗示对我有帮助.
我不知道要开始…
谢谢你的帮助
编辑
public function scopeMarriage($query)
{
return $query->where('LookFor', 'LIKE', '%Ehe%');
}