Hello, I'm struggling with obtaining some related models on custom date ranges. This is a school app that manages members and attendances. Each Member has many Attendance, when the member comes to school, a new record on the attendance table is inserted.
I would like to get some inactivity information to send some emails, for example:
-members who are inactive one week
-members who are inactive two weeks
-members who are inactive one month
-members who are inactive two months
The problem is that those members that are inactive for example one month, are also inactive one week, so if I send an email to inactive members from one week, also other inactive members are going to get this email.
I can get those ranges mentioned earlier, for example:
//Member.php
public function oneWeekInactive(){
$date = new Carbon;
$start = $date->copy()->subDays(8);
$end = $date->copy();
return $this->hasMany('App\Attendance')->whereBetween('scan_date', array($start, $end));
}
In my controller the query for those members is:
$members_to_notify = \App\Member::withoutGlobalScope(SchoolScope::class)
->whereNotNull('email')
->doesntHave('oneWeekInactive')
->get();
So my first question is, do you think I need to redefine those ranges as:
-members who are inactive ONLY one week
-members who are inactive ONLY two weeks
-members who are inactive ONLY one month
-members who are inactive ONLY two months
If the redefine is correct, how do you think I can get members for the first range
get members with more than one week inactive but not two week inactive
I know I need to subtract those members in some way but I'm stuck.