How to get team_id when creating new record from Relation Manager

I have a Relation Manager ConversionsRelationManager I'm trying to create new record from there but I keep getting team_id doesn't have a default value. I have the normal resource UnitConversionResource and I'm able to create new records there with the team_id being passed correctly
Solution:
Thanks @tomc actually found probaly a safer way since Users can edit values in hidden fields ``` ->headerActions([ Tables\Actions\CreateAction::make()->mutateFormDataUsing(function (array $data): array {...
Jump to solution
2 Replies
tomc
tomcā€¢3mo ago
you can use the "hidden" component and pass the "team_id" (in your ConversionsRelationManager ) that worked for me, below is my "PriceRelationManager.php" for my "CourseResource";
public function form(Form $form): Form
{
return $form
->schema([
Section::make() ->label('Regular Price')
->schema([
Hidden::make('course_id'),
TextInput::make('amount')
->numeric(),
Select::make('currency')
->options([
'GHS' => 'GHā‚µ',
'EUR' => 'EUR',
'USD' => 'USD',
]),
Textarea::make('description'),
Toggle::make('active'),
]),
]);
}
public function form(Form $form): Form
{
return $form
->schema([
Section::make() ->label('Regular Price')
->schema([
Hidden::make('course_id'),
TextInput::make('amount')
->numeric(),
Select::make('currency')
->options([
'GHS' => 'GHā‚µ',
'EUR' => 'EUR',
'USD' => 'USD',
]),
Textarea::make('description'),
Toggle::make('active'),
]),
]);
}
Do make sure to call your relations in the getRelations function within your MainResource, just my thoughts
Solution
Will šŸ‡¬šŸ‡¹
Thanks @tomc actually found probaly a safer way since Users can edit values in hidden fields
->headerActions([
Tables\Actions\CreateAction::make()->mutateFormDataUsing(function (array $data): array {
$data['team_id'] = Filament::getTenant()->id;
return $data;
})
])
->headerActions([
Tables\Actions\CreateAction::make()->mutateFormDataUsing(function (array $data): array {
$data['team_id'] = Filament::getTenant()->id;
return $data;
})
])
As mention in the docs - https://filamentphp.com/docs/3.x/actions/prebuilt-actions/create#customizing-data-before-saving
Want results from more Discord servers?
Add your server
More Posts