F
Filament13mo ago
Jon

How do I create a group of SELECTs with a foreach loop

I am having trouble with my form creation in that I dont know how to go about inserting basic php to generate form data. In this instance, I want to loop through all my Rating tags in the database along with the choices for each. but I dont know how to do this within the schema The available rating options may change so it needs to be generated dynamically
Section::make('Ratings')
->schema([

foreach($model->hobbyRatings()->where('parent_id',null) as $rating){
Select::make($rating->tag)
->options(function (Builder $query) use ($rating) {
return $query->where('parent_id', $rating->id)->get();
});
}


])

->columnSpanFull(),
Section::make('Ratings')
->schema([

foreach($model->hobbyRatings()->where('parent_id',null) as $rating){
Select::make($rating->tag)
->options(function (Builder $query) use ($rating) {
return $query->where('parent_id', $rating->id)->get();
});
}


])

->columnSpanFull(),
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?