Livewire Blade Syntax
Blade
<div wire:init="loadCachedCollections"></div>
Livewire
public $upgrades;
public function loadCachedCollections()
{
$this->upgrades = $award->upgrades(); // below
// upgrades()
return collect($awards->where('upgrade', 1))->groupBy('award_fleet');
}
Output to blade
{{ $upgrades }} // displays the data
But @foreach in blade
@foreach($upgrades as $k => $v)
@endforeach
Results in
foreach() argument must be of type array|object, null given
Any wrapping of the $upgrades variable in the blade file returns null.
in your function
public function loadCachedCollections()
{
$this->upgrades = $award->upgrades(); // below
// upgrades()
return collect($awards->where('upgrade', 1))->groupBy('award_fleet');
}
the final statement does nothing since your function need not return anything.
You will have an issue if you do not initialise $upgrades to an empty collection since render will be called before you load the data.
My apologies. I included that return fragment for brevity. It's not in the loadCachedCollections() function.
LIVEWIRE
public $upgrades;
public function loadCachedCollections()
{
$award = new VacancyAwards;
$this->upgrades = $award->upgrades();
}
Vacancy Awards Class
public function upgrades()
{
return collect($awards->where('upgrade', 1))->groupBy('award_fleet');
}
But you still got it. I initialized $upgrades as an empty collection on mount and it worked. Thanks.
Please or to participate in this conversation.