F
Filament2mo ago
MZX

I have a custom entry (For Infolist). How to pass data to the view?

I tried this, but this didn't work. I am calling a JS function in the view which needs that data.
public function getViewData(): array
{
// Fetch the pointeau locations
return [
'pointeauLocations' => $this->getPointeauLocations(),
];
}

public function getPointeauLocations()
{
// Assuming the state refers to the `StartRonde` record
$ronde = $this->getRecord()->ronde;

// Fetch the related Pointeaux and map their locations
$locations = $ronde->pointeaux->map(function ($pointeau) {
return $pointeau->location; // Ensure this returns an array or object with lat and lng
})->toArray(); // Convert to array for easy passing to view

// Log the fetched locations
Log::info('Fetched Pointeau Locations:', $locations);

return $locations; // Return the locations
}
public function getViewData(): array
{
// Fetch the pointeau locations
return [
'pointeauLocations' => $this->getPointeauLocations(),
];
}

public function getPointeauLocations()
{
// Assuming the state refers to the `StartRonde` record
$ronde = $this->getRecord()->ronde;

// Fetch the related Pointeaux and map their locations
$locations = $ronde->pointeaux->map(function ($pointeau) {
return $pointeau->location; // Ensure this returns an array or object with lat and lng
})->toArray(); // Convert to array for easy passing to view

// Log the fetched locations
Log::info('Fetched Pointeau Locations:', $locations);

return $locations; // Return the locations
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server