call(function(){ $zipname = 'do_'.Carbon::today()->format('Y_m_d').'.zip'; $zip = new ZipArchive; $zip->open($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 = public_path($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'); $message->subject('DO for bookings on '.Carbon::today()->format('d/m/Y')); $message->attach($attachment); }); File::delete($zipname); })->everyMinute(); } /** * Register the commands for the application. * * @return void */ protected function commands() { $this->load(__DIR__.'/Commands'); require base_path('routes/console.php'); } }