Theford
Explore posts from serversBest practice for handling optional many-to-many relationships with conditional fields in Filament P
Hello Filament community!
I'm working on a project where I have a many-to-many relationship between Items and Nutritional Information, connected through a pivot table. The nutritional information is optional and depends on an enum in the items table.
I'm struggling to set this up properly in Filament. I've tried several approaches, but they all feel like hacks and are causing issues down the line. Here's an example of what I've tried:
```php
public static function getNutritionBuilder()
{
$nutritionInformation = ItemNutritionInformation::all();
return Forms\Components\Tabs\Tab::make('Nutritions')
->schema(
$nutritionInformation->map(function ($item) {
return Forms\Components\Group::make([
Forms\Components\TextInput::make("nutritional_attributes.{$item->id}.value")
->label($item->name)
->numeric()
->required(),
]);
})->toArray()
)
->columns(2);
}
What is a proper way to set this one up nicely in filament?
Thanks in advance!
2 replies
How to Implement Multi-Tenancy with Admin View Option in FilamentPHP v3?
Hi everyone,
I'm using FilamentPHP v3 and need advice on implementing a multi-tenancy setup with the following requirements:
1. Tenant Selection:
- Users can select a tenant and only see data related to that tenant.
2. Admin View:
- Certain users (admin) can opt to stay without selecting a tenant and have a global view of all data.
Current Status:
- No external multi-tenancy packages used yet.
- Planning to implement roles for normal users vs. admin users.
Questions:
- What are my options within Filament to achieve this setup?
- How can I configure Filament to allow tenant selection while providing an admin view for users with the admin role?
Any guidance or examples would be greatly appreciated!
Thanks!
17 replies