Melomancheto
Melomancheto
FFilament
Created by Melomancheto on 11/7/2024 in #❓┊help
How to handle selected relations during creating a record in handleRecordCreation
I did end up using the following
private static function buildRolesField(): Select
{
return Select::make('roles')
->relationship(
name: 'roles',
titleAttribute: 'name',
modifyQueryUsing: Utils::modifyQueryUsingCheckForAdmin(
auth()->user(),
fn (Builder $query) => $query->where('roles.' . config('permission.column_names.team_foreign_key'), Filament::getTenant()->id)
)
)
->saveRelationshipsUsing(fn (Model $record, $state, Forms\Get $get) => $record->roles()->syncWithPivotValues($state, [config('permission.column_names.team_foreign_key') => $get(config('permission.column_names.team_foreign_key'))]))
->multiple()
->preload()
->searchable();
}
private static function buildRolesField(): Select
{
return Select::make('roles')
->relationship(
name: 'roles',
titleAttribute: 'name',
modifyQueryUsing: Utils::modifyQueryUsingCheckForAdmin(
auth()->user(),
fn (Builder $query) => $query->where('roles.' . config('permission.column_names.team_foreign_key'), Filament::getTenant()->id)
)
)
->saveRelationshipsUsing(fn (Model $record, $state, Forms\Get $get) => $record->roles()->syncWithPivotValues($state, [config('permission.column_names.team_foreign_key') => $get(config('permission.column_names.team_foreign_key'))]))
->multiple()
->preload()
->searchable();
}
16 replies
FFilament
Created by Melomancheto on 11/11/2024 in #❓┊help
Multi-tenancy for models with no direct relation to user
so If I do that and for example go in the GameMedia Resource and I add protected static ?string $tenantOwnershipRelationshipName = 'game'; it should work, right? It will know that the ownership of the organization is contained by the game I've tested it and it works, but I just wan to be sure that I understand
9 replies
FFilament
Created by Melomancheto on 11/11/2024 in #❓┊help
Multi-tenancy for models with no direct relation to user
First of all, thank you @arnaudsf for trying to help. SO the idea is that I have a Game Resource, this resource is splitted into 2-3 resources for ease of the user. They are: - Game Application - Game Media They are both related to the Game. The game itself is tied to a user, who is tied to a Organization. I don't know if I'm going the right way, but I consider them as tenant resources, because they need to be managed by the organization
9 replies
FFilament
Created by Melomancheto on 11/11/2024 in #❓┊help
Multi-tenancy for models with no direct relation to user
Someonе? 🥹
9 replies
FFilament
Created by Melomancheto on 11/7/2024 in #❓┊help
How to handle selected relations during creating a record in handleRecordCreation
This is the full UserResource @Leandro Ferreira, thank you
16 replies
FFilament
Created by Melomancheto on 11/7/2024 in #❓┊help
How to handle selected relations during creating a record in handleRecordCreation
I've tried both but none of them worked.
16 replies
FFilament
Created by Melomancheto on 11/7/2024 in #❓┊help
How to handle selected relations during creating a record in handleRecordCreation
I will try the dehydrate tomorrow, thank you
16 replies
FFilament
Created by Melomancheto on 11/7/2024 in #❓┊help
How to handle selected relations during creating a record in handleRecordCreation
return $form
->schema([
Forms\Components\Fieldset::make('User')
->schema([
self::buildNameField(),
self::buildEmailField(),
self::buildPasswordField(),
self::buildOrganizationsFields(),
]),
Forms\Components\Fieldset::make('Permissions')
->schema([
self::buildRolesField(),
self::buildPermissionsField(),
])->mutateRelationshipDataBeforeCreateUsing(function ($record, $data) {
$data['organization_id'] = Filament::getTenant()->id;
return $data;

})
]);
return $form
->schema([
Forms\Components\Fieldset::make('User')
->schema([
self::buildNameField(),
self::buildEmailField(),
self::buildPasswordField(),
self::buildOrganizationsFields(),
]),
Forms\Components\Fieldset::make('Permissions')
->schema([
self::buildRolesField(),
self::buildPermissionsField(),
])->mutateRelationshipDataBeforeCreateUsing(function ($record, $data) {
$data['organization_id'] = Filament::getTenant()->id;
return $data;

})
]);
Since you are here I can see that I need to attach this after the schema, but I get the same error again. https://filamentphp.com/docs/3.x/forms/fields/repeater#mutating-related-item-data-before-creating It's not hitting the callback, it throws an error before that.
16 replies
FFilament
Created by Melomancheto on 11/7/2024 in #❓┊help
How to handle selected relations during creating a record in handleRecordCreation
I will go and have a look at it
16 replies
FFilament
Created by Melomancheto on 11/7/2024 in #❓┊help
How to handle selected relations during creating a record in handleRecordCreation
I was looking at the selection docs 😄 but I guess I need to look there too, thanks
16 replies
FFilament
Created by Melomancheto on 11/7/2024 in #❓┊help
How to handle selected relations during creating a record in handleRecordCreation
No description
16 replies
FFilament
Created by Melomancheto on 11/5/2024 in #❓┊help
Define a custom route with custom view in Filament
When I add it to the getPages and it extends SimplePage
10 replies
FFilament
Created by Melomancheto on 11/5/2024 in #❓┊help
Define a custom route with custom view in Filament
No description
10 replies
FFilament
Created by Melomancheto on 11/5/2024 in #❓┊help
Define a custom route with custom view in Filament
for example here:
public static function getPages(): array
{
return [
'index' => Pages\ListOrganizations::route('/'),
'create' => Pages\CreateOrganization::route('/create'),
'edit' => Pages\EditOrganization::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListOrganizations::route('/'),
'create' => Pages\CreateOrganization::route('/create'),
'edit' => Pages\EditOrganization::route('/{record}/edit'),
];
}
And just hide it in the navigation?
10 replies
FFilament
Created by Melomancheto on 11/5/2024 in #❓┊help
Define a custom route with custom view in Filament
and how can I define the route to that page? In the Resource?
10 replies
FFilament
Created by Melomancheto on 11/5/2024 in #❓┊help
Define a custom route with custom view in Filament
No description
10 replies