Laravel 获取多选选定值

Laravel 获取多选选定值,laravel,request,multi-select,Laravel,Request,Multi Select,我需要获取多选选定值: 通过简单的选择,可以很好地使用此方法: public function championships(Request $request) { $nationId = $request->get('q'); return Championship::where('nation_id', $nationId)->get(['id', 'name as text']); } 但我需要获取multiselect中的所有选定值,并使用带有where的数组将其

我需要获取多选选定值:

通过简单的选择,可以很好地使用此方法:

public function championships(Request $request)
{
   $nationId = $request->get('q');
   return Championship::where('nation_id', $nationId)->get(['id', 'name as text']);
}
但我需要获取multiselect中的所有选定值,并使用带有where的数组将其传递给查询

但我不知道如何捕捉多选的价值观


谢谢

如果您想要多选,您必须告诉laravel这是一个值数组,选择框是关于什么的。您可以通过在选择框的名称后面附加“[]”来完成此操作

<select name="q[]">
现在,您需要从一组值中进行选择,而不是从单个值中进行选择,因此,现在您需要的是“where”,而不是“where”:

试试下面这个

champions::select('id','name as text')->where('nation_id',$nationId)->get();
何处陈述

$users=champosion::选择('id','name as text')
->在哪里([
['nation_id','=',$nationaid],
['name','like',$name],
])->get();
或何处声明

$users=champosion::选择('id','name as text')
->其中('nation_id','=',$nationId)
->orWhere('name','like',$name)
->get();

是的,你是这样做的:这是我尝试过的,但是$request->get('q');它只返回一个值。多选
$nationIds = $request->get('q');
return Championship::whereIn('nation_id',$nationIds)->get(['id', 'name as text']);