Select is not working for a BelongsToMany relationship in RelationManager

I have a Team model which has a BelongsToMany relationship with Products, including a pivot table:

class Team extends Model
{

    ///

    public function products(): BelongsToMany
    {
        return $this->belongsToMany(Product::class)
            ->withPivot(
                [
                    'max_persons'
                ])
            ->as('seat')
            ->using(Seat::class)
            ->withTimestamps();
    }

}


and vice versa in Product:

class Product extends Model {

    //
    
    public function teams(): BelongsToMany
    {
        return $this->belongsToMany(Team::class)
            ->withPivot(
                [
                    'max_persons'
                ])
            ->as('seat')
            ->using(Seat::class)
            ->withTimestamps();
    }
}


In my TeamResource I've added:

public static function getRelations(): array
    {
        return [
            RelationManagers\UsersRelationManager::make(),
            RelationManagers\ProductsRelationManager::make()
        ];
    }


And I created a ProductsRelationManager:

class ProductsRelationManager extends RelationManager
{
    protected static string $relationship = 'products';

    public function isReadOnly(): bool
    {
        return false;
    }

    public function form(Form $form): Form
    {
        return $form
            ->schema([

                Section::make('Products')
                    ->schema([
                        Select::make('product')
                            ->relationship('product', 'name')

                    ])
            ]);
    }



The problem is, no matter how I configure the Select, I either can't get any results or I get the error "Call to a member function getResults() on null"

The question therefore is, how can I correctly edit the Product which is attached to the Team using a Select?
Was this page helpful?