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();
}

}
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();
}
}
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()
];
}
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')

])
]);
}
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?
6 Replies
Randak
Randak7mo ago
I had a similar problem that was just solved (in my case I couldn't edit the item without getting that error). It was fixed by removing the "select" statement in the RelationManager.
ironclaw8986
ironclaw8986OP7mo ago
Sorry, I don't follow. Do you mean you could not use Select at all?
Randak
Randak7mo ago
Correct. I'm not sure if you're having exactly the same problem (and I'm new at all this), but removing the select statement fixed the problem for me.
ironclaw8986
ironclaw8986OP7mo ago
Ah ok, thanks. Unfortunately that isn't a solution here, I need the ability to adjust the Produch which is assigned to the Team.
Randak
Randak7mo ago
Good luck!
wdog
wdog7mo ago
I've used a select without relations and used directly options(fn($state):string => ....query.... )
Want results from more Discord servers?
Add your server