当我调用此API时,我收到此错误“此集合实例上不存在Property [date]。”
这是我的API代码。
public function apiGetAttend($id, Request $request)
{
$tokenuser = User::with('attendance')
->where('token', $request->input('token'))->first();
$user = User::with('attendance')->find($id);
if($user && $tokenuser == $user){
return response()->json([
'MacAddress' => $user->mac_address,
'SerialNo'=>$user->serial_no,
'Date' => $user->attendance->date,
'Time' => $user->attendance->time,
'Present' => $user->attendance->present
]);
}
return response()->json([
'status' => 'Fail',
'message' => 'You dont have access to see this user.'
]);
}
答案 0 :(得分:0)
由于用户有很多人,'Date' => $user->attendance->first()->date,
'Time' => $user->attendance->first()->time,
'Present' => $user->attendance->first()->present
是一个集合,而不是一个对象。因此,您可能希望迭代它和所有出席日期等。或者您可以使用first()
收集方法从集合中的第一次出席中获取数据:
u32_t d = (foo >> 24) & 0xFF; // Get the bits 32nd...25th
u32_t c = (foo >> 16) & 0xFF; // 24th...17th
u32_t b = (foo >> 8) & 0xFF; // 16th...9th
u32_t a = (foo) & 0xFF; // 8th...1st