0

UsermailRespoitory

I want the days should be added inside addDays() The days i will get frm my database

public function create() 
    {

        $users = User::where('user_type', 2)->get();
        $auto_email_templates=AutoEmailTemplate::all()->pluck('days');


        foreach ($users as $user) {

           if( $user->created_at > Carbon::now()->addDays($days)){
                if ($user->created_at < Carbon::now()) //signup
                {    
                    return false;
                }
                    Mail::to($user)->send(new Automail($template));
                    return true;

           }
}
Narayan Acharya
  • 1,459
  • 1
  • 18
  • 33
  • 3
    `if( $user->created_at > Carbon::now()->addDays($days)){`there is no days variable – Andy Song Feb 07 '20 at 03:02
  • > "I want the days should be added inside addDays() The days i will get frm my database" So do this... `$days= //however you get days from your database` – James Feb 07 '20 at 04:01

1 Answers1

0
  public function create() 
    {

        $users = User::where('user_type', 2)->get();
        $auto_email_templates=AutoEmailTemplate::all();


        foreach ($users as $user) {
            foreach($auto_email_templates as $mail){

                if( $user->created_at > Carbon::now()->addDays($mail->days)){
                        if ($user->created_at < Carbon::now()) //signup
                        {    
                            return false;
                        }
                            Mail::to($user)->send(new Automail($template));
                            return true;

                }
Dilip Hirapara
  • 14,810
  • 3
  • 27
  • 49