3 回答
TA贡献1865条经验 获得超7个赞
试试这个
$teachers = DB::table('users')->where('role', '=', 1);
$teacher = Users::all();
return new UserResource($teachers);
TA贡献1890条经验 获得超9个赞
return UserResource::collection(User::where('role', '=', 1)->get());这应该对你有用,你能试试吗?
更新
您仍然可以将表与 连接,但如果您真的想使用eloquentDB::Table()
然后你必须像这样指定你的方法。toArray()
public function toArray($request)
{
// return parent::toArray($request);
return [
'role' => $this->role,
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
并会给你结果。return UserResource::collection(DB::table('users')->where('role', '=', 1)->get());
- 3 回答
- 0 关注
- 93 浏览
添加回答
举报