ironclaw8986
ironclaw8986
FFilament
Created by ironclaw8986 on 9/10/2024 in #❓┊help
Adjusting Filament Chart Widgets in Laravel Breeze?
No description
4 replies
FFilament
Created by ironclaw8986 on 6/11/2024 in #❓┊help
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?
7 replies