if ($sport?->name == "Football") {
$schema[] = Actions::make([
Action::make("add_commentary")->label('Add Commentary')
->form([
Textarea::make('commentary')->label("Add to Commeny for Football Match")
])
->action(function ($data, $record) use ($competitionMatchInsights) {
if (isset($data["commentary"])) {
foreach ($competitionMatchInsights as $matchInsight) {
$newEntry = [ 'event' => "custom commentary",'sentence' => $data["commentary"] ];
$commentaryData = $matchInsight->commentary;
$commentaryData[] = $newEntry;
$matchInsight->update(['commentary' => $commentaryData]);
to_route('filament.admin.resources.match-lists.view', ['record' => $record->id]);
}
}
})
]);
$schema[] = RichEditor::make("football_commentary")
->afterStateHydrated(function ($component) use ($competitionMatchInsights) {
$test = [];
foreach ($competitionMatchInsights as $commentaryEntry) {
foreach (array_reverse($commentaryEntry->commentary) as $commentaryEntryData) {
$commentaryText = "<p>" . $commentaryEntryData["sentence"] . "</p>";
$test[] = $commentaryText;
}
}
return $component->state(implode("", $test));
});
}