【发布时间】:2020-02-20 03:27:09
【问题描述】:
当我运行这段代码时:
public function manager_employee_list()
{
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
$identities = DB::table('appraisal_identity')->select('id')->where('company_id', $userCompany)->where('is_current', 1)->first();
$linemanager = DB::table('hr_employees')->select('line_manager_id')->where('id', $userEmployee)->first();
$linemanageremployee = DB::table('hr_employees')->select('id')->where('line_manager_id', $linemanager->line_manager_id)->get();
$goals = AppraisalGoal::where('employee_id', $linemanageremployee)->where('appraisal_identity_id',
return view('appraisal.appraisal_goals.manager_employee_list')->with('goals', $goals);
}
我收到了这个错误:
stdClass 类的对象无法转换为字符串
当我这样做时:
dd($linemanageremployee);
我明白了:
Illuminate\Support\Collection {#880 ▼
#items: array:3 [▼
0 => {#2312 ▼
+"id": 2
}
1 => {#2326 ▼
+"id": 3
}
2 => {#2313 ▼
+"id": 6
}
]
}
我该如何解决?
谢谢。
【问题讨论】:
-
Try the docs。
get()返回一个集合,正如您的dd()所示。集合就像一个数组——不是一个东西,而是一组东西。在您的示例中,您的数据库查询返回 3ids。您需要遍历集合中的每个项目才能使用它们。
标签: laravel