invoice = $invoice; } /** * Execute the console command. * * @return mixed */ public function handle() { $force = $this->option('force'); $account = $this->argument('account'); $accounts = null; if ($account) { $accounts = Account::find($account)->get(); } else { $accounts = Account::all(); } $latestInvoice = $this->invoice->latest()->first(); $invoiceYear = Carbon::parse($latestInvoice->created_at)->year; if(Carbon::now()->year > $invoiceYear || $force) { $accounts->transform(function ($a) { /** @var Account $a */ $a->invoice_number_counter = 1; $a->update(); }); $this->info('The counter has been resetted successfully for '.$accounts->count().' account(s).'); } } }