needsOnboarding = $tracker === null; $this->count = $tracker === null ? 0 : $tracker->count; $this->value = $this->count; } public function initialise(): void { $this->validate(); $tracker = Tracker::current() ?? Tracker::create([ 'label' => 'Counter', 'unit' => 'units', 'count' => $this->value, ]); $this->count = $tracker->count; $this->needsOnboarding = false; } public function increment(): void { $tracker = Tracker::current(); if (! $tracker || $tracker->count >= self::MAX_COUNT) { return; } $tracker->increment('count'); $tracker->refresh(); $this->count = $tracker->count; $this->value = $this->count; } public function edit(): void { $this->value = $this->count; $this->resetValidation(); $this->editing = true; } public function save(): void { $this->validate(); $tracker = Tracker::current(); if (! $tracker) { return; } $tracker->update(['count' => $this->value]); $this->count = (int) $this->value; $this->editing = false; } public function cancel(): void { $this->value = $this->count; $this->resetValidation(); $this->editing = false; } public function render(): View { return view('livewire.counter')->layout('layouts.app'); } }