I am trying to send email three days before the expired date,
but I'm not sure how to?
Logic
- Retrieve all subscribers that are three days left to expire
- Send email to their users
Code
Table I need to check timestamps named subscribes.
$subscribes = Subscribe::all();
This table has a column named expires_at
which I need to check this for finding 3 days left.
And my mailing
Mail::to($user->email)->send(new SubscribeExpire($user, $subscribe));
I'm confused with this Carbon calculation thing, anyone can help with that?
Update
based on answer below now I have this:
$subscribes = Subscribe::where('expires_at', Carbon::now()->subDays(3))->get();
$user = [];
$package = [];
foreach($subscribes as $subscribe){
$user = User::where('email', $subscribe->email);
$package = Package::where('id', $subscribe->package_id);
}
Mail::to($user->email)->send(new SubscribeExpire($user, $package));
but when I run the command it get this error
ErrorException : Trying to get property 'email' of non-object