如何更改以下模型请求以仅获取特定字段?
Event::whereIn("idEvent", $this->ids)->get();
我尝试过:
Event::select(["name", "id"])->whereIn("idEvent", $this->ids)->get();
答案 0 :(得分:4)
您应该尝试
Event::whereIn("idEvent", $this->ids)->pluck(["id", "name"]);
答案 1 :(得分:0)
您可以尝试以下方法吗?
Event::whereIn("idEvent", $this->ids)->get(['name', 'id']);
答案 2 :(得分:-1)
Event :: where(“ idEvent”,$ this-> ids)-> select('name','id')-> get(); 您可以使用select选择特定的模型属性(该模型在DB中的列)。
上面将选择事件模型的名称和ID,idEvent是$ this-> ids。