© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
8 replies
Askancy

Multiple Select with BelongsToMany relationship

I'm just recently using Filamentphp and need to get into the mindset of how it works.

I have two sql tables:

Article
Article_pivot_games

In article_pivot_games I have the columns:

- id
-article_id
-games_id

now I need a multiple select, where he fills in the select with the names of the games that have the article_id equal to the id of the article I am editing.

Select::make('id_game[]')
    ->label('Games:')
    ->relationship('games', 'name')
    ->multiple()
    ->searchable()
    ->required(),  
Select::make('id_game[]')
    ->label('Games:')
    ->relationship('games', 'name')
    ->multiple()
    ->searchable()
    ->required(),  

in the model Article.php

public function games(): BelongsToMany
{
    return $this->belongsToMany(Games::class, 'article_pivot_games', 'games_id');
}
public function games(): BelongsToMany
{
    return $this->belongsToMany(Games::class, 'article_pivot_games', 'games_id');
}


However, how do I tell the select to use that function? Also am I using the right method?

Before filamentphp I used a custom admin of my own, in which I had a column in Article with the id_games column containing "1,6,123,532," and I used this:

$pickup_games = explode(',', $articles->id_gioco);
$game_list = [];
foreach ($pickup_games as $pickup_game) {
    $game_list [] = Games::where('id', $pickup_game)->first();
}
$pickup_games = explode(',', $articles->id_gioco);
$game_list = [];
foreach ($pickup_games as $pickup_game) {
    $game_list [] = Games::where('id', $pickup_game)->first();
}
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Single select with belongsToMany relationship
FilamentFFilament / ❓┊help
3mo ago
Select with BelongsToMany without multiple()?
FilamentFFilament / ❓┊help
3y ago
Relationship belongstoMany
FilamentFFilament / ❓┊help
3y ago
multiple relationships with ->relationship()
FilamentFFilament / ❓┊help
3y ago