Basically, Now the email sending one time only. I need the email need send again after 30 days. Can anyone help me with this?
public function create()
{
$users = User::where('user_type', 2)->get();
$auto_email_templates=AutoEmailTemplate::all();
foreach($auto_email_templates as $mail) {
foreach ($users as $user) {
if( $user->created_at < Carbon::now()->subDays($mail->days)){
$email_id = $mail->id;
$user_id = $user->id;
if (EmailSave::where('email_id',$email_id)->where('user_id',$user_id)->count()< 1){
if (condition) { //mail sent again after 30 days
# code...
$mail = new EmailSave;
$mail->user_id = $user->id;
$mail->email_id =$mail->id;
Mail::to($user->email)->send(new Automail($mail));
$mail->save();
}
}
}