call(function(){ $zipname = 'do_'.Carbon::today()->format('Y_m_d').'.zip'; $zip = new ZipArchive; $zip->open(storage_path('tempdir').'/'.$zipname, ZipArchive::CREATE); $approvedInvoices = InvoiceStatuses::where('status', 'approve')->whereDate('created_at', Carbon::today())->distinct()->get(['invoice_id']); $bookings = []; foreach($approvedInvoices as $approved){ $bookings[] = $approved->invoice->booking->id; } foreach ($bookings as $id) { $do = app(InvoiceController::class)->generateSupplierDo($id); $zip->addFromString('do_'.Carbon::today()->format('Y_m_d').'_'.$id.'.pdf', $do->Output('do.pdf', 'S')); } $zip->close(); $attachment = storage_path('tempdir').'/'.$zipname; Mail::raw( 'DO for bookings po approved on '.Carbon::today()->format('d/m/Y'), function($message) use ($attachment){ $message->from('exchange@cief-malaysia.com'); $message->to(['uldvstar@gmail.com', 'pm@cief-malaysia.com', 'hasan@cief-malaysia.com', 'hasanakbar27@gmail.com']); $message->subject('DO for bookings on '.Carbon::today()->format('d/m/Y')); $message->attach($attachment); }); File::delete(storage_path('tempdir').'/'.$zipname); })->everyMinute(); } /** * Register the commands for the application. * * @return void */ protected function commands() { $this->load(__DIR__.'/Commands'); require base_path('routes/console.php'); } }