0
votes

I am trying to send mail to user. I don't know why its shows error.

$unUsedModuleIds=!$modulesIds->whereIn('id',$usedModuleIds)->exists();

when add this statement it's showing error.

foreach ($ModuleAutoMail as $module) {
    if ($mail->condition_id == '3') {

        $last_used_module = Carbon::parse($module->last_used_module);
        $DeferenceInDays = Carbon::parse(Carbon::now())->diffInDays($last_used_module);

        $usedModuleIds = module_auto_mail::where('user_id', $user_id)->pluck('module_id');
        $unUsedModuleIds = !$modulesIds->whereIn('id', $usedModuleIds)->exists();


        if ($unUsedModuleIds) {
            $ableToSendMail = true;
        }

        if ($DeferenceInDays > 7) {
            $ableToSendMail = false;
        }

    }
}
1
Can you add how you retrieve $modulesIds?Lizesh Shakya

1 Answers

0
votes

Try this

foreach($ModuleAutoMail as $module) {

    if($mail->condition_id=='3' ){  

        $last_used_module = Carbon::parse($module->last_used_module);
        $DeferenceInDays = Carbon::parse(Carbon::now())->diffInDays($last_used_module);

        $usedModuleIds = module_auto_mail::where('user_id',$user_id)->pluck('module_id')->toArray();
        $unUsedModuleIds= module_auto_mail::whereIn('id',array_values($usedModuleIds))->get();


        if(count($unUsedModuleIds) > 0){
            $ableToSendMail = true;
        }

        if ($DeferenceInDays > 7) {
            $ableToSendMail = false;
         }

    }
}