I'm creating database notifications. I have 2 Notification classes: InterviewRequestReceived.php:
$user = Auth::user();
$interviewRequestReceived = InterviewRequestsReceived::latest()->where('user_id', $user->id)->get();
return [
'date_time1' => $interviewRequestReceived[$interviewRequestReceived->count() - 1]->latest()->get('date_time1'),
'date_time2' => $interviewRequestReceived[$interviewRequestReceived->count() - 1]->latest()->get('date_time2')
];
and InterviewRequestSent.php:
public function toDatabase($notifiable)
{
$user = Auth::user();
$interviewRequestSent = InterviewRequestsSent::latest()->where('user_id', $user->id)->get();
return [
'date_time1' => $interviewRequestSent[$interviewRequestSent->count() - 1]->latest()->get('date_time1'),
'date_time2' => $interviewRequestSent[$interviewRequestSent->count() - 1]->latest()->get('date_time2')
];
}
I have 3 tables. interview_requests_receiveds, interview_requests_sents and I created the notifications table and migrated. On my form I have 2 options for datetime fields, so Employers can choose 2 possible date and times that would work for them to interview a candidate. My form is working. My notifications are working except it's inserting all of the logged in Users' date and times, instead of just the last inserted record.
I'm trying to use latest(), but it's not working.