-
app/Console/Commands/CheckInvoiceStatus.php
Open in GitHubuse Carbon\Carbon; use Crater\Models\Invoice; use Illuminate\Console\Command; class CheckInvoiceStatus extends Command { protected $signature = 'check:invoices:status'; protected $description = 'Check invoices status.'; public function __construct() { parent::__construct(); } public function handle() { $date = Carbon::now(); $invoices = Invoice::where('status', '<>', Invoice::STATUS_COMPLETED)->whereDate('due_date', '<', $date)->get(); foreach ($invoices as $invoice) { $invoice->status = Invoice::STATUS_OVERDUE; printf("Invoice %s is OVERDUE \n", $invoice->invoice_number); $invoice->save(); } } }
-
app/Console/Kernel.php
Open in GitHubuse Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; class Kernel extends ConsoleKernel { // protected function schedule(Schedule $schedule) { $schedule->command('check:invoices:status') ->daily(); // } // }