我有多个query
joins
条件,我试图将array
从我的控制器传递到model
然后传递{{1}查询结果。我收到这个错误:
类Illuminate \ Database \ Eloquent \ Collection的对象无法转换为int
有人可以帮我找到原因吗?
return
public function get_session_leave_tagv2()
{
$employee = [0 => 0];
if(Session::has('employee_leave_tag'))
{
$employee = Session::get('employee_leave_tag');
}
$emps = Tbl_payroll_leave_employeev2::select('payroll_employee_id')->whereIn('payroll_leave_employee_id',$employee)->get();
$emp = Tbl_payroll_leave_schedulev2::getallemployeeleavedata($emps)->get();
$data['new_record'] = $emp;
return json_encode($data);
}
答案 0 :(得分:1)
如果您使用的是控制器,他们会避免使用手动json_encode,而是选择以下方式
public function get_session_leave_tagv2()
{
$employee = [0 => 0];
if(Session::has('employee_leave_tag'))
{
$employee = Session::get('employee_leave_tag');
}
$emps = Tbl_payroll_leave_employeev2::select('payroll_employee_id')->whereIn('payroll_leave_employee_id',$employee)->get();
$emp = Tbl_payroll_leave_schedulev2::getallemployeeleavedata($emps)->get();
$data['new_record'] = $emp;
return response()->json($data);
}