Sure! When using Filament v4's RelationManagers (such as DealRelationManager within your CustomerResource), Filament automatically manages the relationship for you. Specifically, when creating a new Deal via the RelationManager, you don't need to manually select the customer_id—it should be assigned under the hood by Filament.
However, if you want to show the field (for reference) but keep it read-only/pre-filled, or hide it entirely, here's how you can approach it:
1. You Don't Need to Show customer_id In the Create Form
Normally, Filament will automatically associate the new Deal with the parent Customer, so you can simply remove the customer_id Select field from your Deal form schema inside the RelationManager. (That's the recommended way.)
2. If You Want to Show It as a Disabled/Read-Only Field
If you want to show the field for informational purposes (e.g. disabled or read-only), you can use the disabled() or readOnly() methods, and prefill the value with the parent record's ID.
Example:
// In your DealRelationManager
public static function form(Form $form): Form
{
return $form
->schema([
// Other Deal fields...
// Show customer_id as disabled (optional)
Select::make('customer_id')
->label('Customer')
->options(Customer::all()->pluck('name', 'id'))
->default(fn ($livewire) => $livewire->getOwnerRecord()->id)
->disabled()
->required(),
]);
}
default(fn ($livewire) => $livewire->getOwnerRecord()->id)sets the value to the parent Customer ID..disabled()will make the field non-editable.
3. Completely Hide the customer_id Field
You can also exclude the customer_id field from the form in your RelationManager. Filament will link the new Deal to its parent Customer as expected.
// Just don't include a customer_id field in your schema inside DealRelationManager
public static function form(Form $form): Form
{
return $form
->schema([
// Only add the other Deal fields (not customer_id)
]);
}
Recap
- Filament sets the foreign key automatically inside RelationManager.
- Don’t add
customer_idto the form unless you have a specific need. - If you must display it, set it as disabled/read-only with the default from the owner record.
That's all you need! If it doesn't work as expected, make sure your relationships (hasMany, belongsTo) are set up correctly in your models.