How are you using days in the Component's view template?
Is it supposed to be a Computed Property? Were you expecting the result to be cached between requests?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi. I've face strange behaviour. after clicking button which calls 'sync' method which has temporary sleep() function in it, i'm getting errors which is cause because my activities property has become an array of empty arrays as i can see after logging. (or collection of empty collections). I'm getting exception from days method about $a->date being null.
days() method even called again after sync? looks like i don't understand how rerendering workslocal.DEBUG: $this->activities[[],[],[],[],[],[],[]] <?php
use Livewire\Volt\Component;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use App\Services\Strava;
use Illuminate\Support\Collection;
use Carbon\Carbon;
use Livewire\Attributes\Computed;
new
#[Layout('layouts.app')]
#[Title('Activities')]
class extends Component {
public Collection $activities;
public Carbon $after;
public Carbon $before;
public Carbon $currentDate;
public string $prevButtonLink;
public ?string $nextButtonLink;
public function mount(Strava $strava)
{
$this->currentDate = now();
$this->after = $this->currentDate->copy()->startOfMonth();
$this->before = $this->currentDate->copy()->endOfMonth();
$this->activities = $strava->getActivities($this->after, $this->before);
}
public function days(): Collection
{
$allDates = collect();
\Illuminate\Support\Facades\Log::debug('$this->activities' . $this->activities);
for ($currentDate = $this->after->copy(); $currentDate <= $this->before; $currentDate->addDay()) {
$data = collect([
'date' => $currentDate->copy(),
'activities' => $this->activities->filter(fn($a) => $currentDate->isSameDay($a->date))->values(),
]);
$allDates->put($currentDate->format('d.m'), $data);
}
return $allDates;
}
public function sync()
{
sleep(2);
}
}; ?>
Please or to participate in this conversation.