get(); foreach($template as $key => $a) { foreach($compound as $c){ $tempoh = new Carbon($c->created_at); $diff = $tempoh->diffInDays($now); if($a->status == 'aktif'){ if(count($c->LetterNotice) > 0){ foreach ($c->LetterNotice as $key => $l) { if($l->no_rujukan != $a->no_rujukan){ if($a->tempoh_hantar == "13"){ if($diff < 14){ $dataLetter = [ "tempoh_hantar" => $a->tempoh_hantar, "jenis_amaran" => $a->jenis_amaran, "alasan" => "Sebelum tempoh 14 hari", "no_rujukan" => $a->no_rujukan, "subjek" => $a->subjek, "kandungan" => $a->kandungan, "no_pos" => "", ]; $c->letternotice()->create($dataLetter); } }else if($a->tempoh_hantar == "14"){ if($diff >= 14){ $dataLetter = [ "tempoh_hantar" => $a->tempoh_hantar, "jenis_amaran" => $a->jenis_amaran, "alasan" => "Selepas tempoh 14 hari", "no_rujukan" => $a->no_rujukan, "subjek" => $a->subjek, "kandungan" => $a->kandungan, "no_pos" => "", ]; $c->letternotice()->create($dataLetter); } }else if($a->tempoh_hantar == "28"){ if($diff > 28){ $dataLetter = [ "tempoh_hantar" => $a->tempoh_hantar, "jenis_amaran" => $a->jenis_amaran, "alasan" => "Selepas tempoh 28 hari", "no_rujukan" => $a->no_rujukan, "subjek" => $a->subjek, "kandungan" => $a->kandungan, "no_pos" => "", ]; $c->letternotice()->create($dataLetter); } } } } }else { if($a->tempoh_hantar == "13"){ if($diff < 14){ $dataLetter = [ "tempoh_hantar" => $a->tempoh_hantar, "jenis_amaran" => $a->jenis_amaran, "alasan" => "Selepas tempoh 28 hari", "no_rujukan" => $a->no_rujukan, "subjek" => $a->subjek, "kandungan" => $a->kandungan, "no_pos" => "", ]; $c->letternotice()->create($dataLetter); } }else if($a->tempoh_hantar == "14"){ if($diff >= 14){ $dataLetter = [ "tempoh_hantar" => $a->tempoh_hantar, "jenis_amaran" => $a->jenis_amaran, "alasan" => "Selepas tempoh 28 hari", "no_rujukan" => $a->no_rujukan, "subjek" => $a->subjek, "kandungan" => $a->kandungan, "no_pos" => "", ]; $c->letternotice()->create($dataLetter); } }else if($a->tempoh_hantar == "28"){ if($diff > 28){ $dataLetter = [ "tempoh_hantar" => $a->tempoh_hantar, "jenis_amaran" => $a->jenis_amaran, "alasan" => "Selepas tempoh 28 hari", "no_rujukan" => $a->no_rujukan, "subjek" => $a->subjek, "kandungan" => $a->kandungan, "no_pos" => "", ]; $c->letternotice()->create($dataLetter); } } } } } } } }