Randak
Randak
FFilament
Created by ironclaw8986 on 6/11/2024 in #❓┊help
Select is not working for a BelongsToMany relationship in RelationManager
Good luck!
7 replies
FFilament
Created by Randak on 6/9/2024 in #❓┊help
Editing a many-to-many attachment with pivot attributes.
I solved the problem by removing the "shield_id" select statement.
6 replies
FFilament
Created by ironclaw8986 on 6/11/2024 in #❓┊help
Select is not working for a BelongsToMany relationship in RelationManager
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.
7 replies
FFilament
Created by ironclaw8986 on 6/11/2024 in #❓┊help
Select is not working for a BelongsToMany relationship in RelationManager
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.
7 replies
FFilament
Created by Randak on 6/9/2024 in #❓┊help
Editing a many-to-many attachment with pivot attributes.
The closest I've got is adding
->multiple
->multiple
Select:make(shield_id) That allows me to open the edit form, but does not pre-populate the shield description. When I click on that field it brings up the search (no dropdown) and then errors when I type anything. The other fields seem to edit fine.
6 replies
FFilament
Created by Randak on 6/9/2024 in #❓┊help
Editing a many-to-many attachment with pivot attributes.
class ShieldsRelationManager extends RelationManager
{
protected static string $relationship = 'shields';

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('shield_id')
->relationship('shield', 'description')
->required(),
Forms\Components\Select::make('combat_action')
->required()
->options([
'attack' => 'Attack',
'parry' => 'Parry',
]),
Forms\Components\TextInput::make('fame_points')
->required()
->integer(),
]);
}

public function table(Table $table): Table
{
return $table
->allowDuplicates()
->recordTitleAttribute('description')
->columns([
Tables\Columns\TextColumn::make('description')
->sortable(),
Tables\Columns\TextColumn::make('combat_action')
->sortable(),
Tables\Columns\TextColumn::make('fame_points')
->sortable(),

])
->headerActions([
Tables\Actions\AttachAction::make()
->preloadRecordSelect()
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\Select::make('combat_action')
->options([
'attack' => 'Attack',
'parry' => 'Parry',
])
->required(),
Forms\Components\TextInput::make('fame_points')
->numeric()
->required(),
]),
])
class ShieldsRelationManager extends RelationManager
{
protected static string $relationship = 'shields';

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('shield_id')
->relationship('shield', 'description')
->required(),
Forms\Components\Select::make('combat_action')
->required()
->options([
'attack' => 'Attack',
'parry' => 'Parry',
]),
Forms\Components\TextInput::make('fame_points')
->required()
->integer(),
]);
}

public function table(Table $table): Table
{
return $table
->allowDuplicates()
->recordTitleAttribute('description')
->columns([
Tables\Columns\TextColumn::make('description')
->sortable(),
Tables\Columns\TextColumn::make('combat_action')
->sortable(),
Tables\Columns\TextColumn::make('fame_points')
->sortable(),

])
->headerActions([
Tables\Actions\AttachAction::make()
->preloadRecordSelect()
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\Select::make('combat_action')
->options([
'attack' => 'Attack',
'parry' => 'Parry',
])
->required(),
Forms\Components\TextInput::make('fame_points')
->numeric()
->required(),
]),
])
6 replies