tg
tg
FFilament
Created by tg on 7/24/2024 in #❓┊help
Determine if form is in modal inside a configureUsing closure?
Is there a way to determine inside the Forms\Component\Tabs::configureUsing closure if the Tabs component is rendered inside an action modal container? Context I've enabled Forms\Components\Tabs::persistTabInQueryString() (docs) globally through a Tabs::configureUsing closure. This works as expected on resource pages. However, some of my forms with tabs also appear inside action modals. The tab persistence works there as well, but does not make sense as the modal state itself is not persisted across browser tabs – which is expected behavior. While it does not break my app right now, I guess it will introduce conflicts sooner or later when a tab on the page has the same name as a tab inside the modal. Definitely the case once I open a resource form inside a modal on top of a resource page that has the same resource type.
2 replies
FFilament
Created by tg on 4/2/2024 in #❓┊help
Modal action or table inside form
No description
15 replies
FFilament
Created by tg on 2/19/2024 in #❓┊help
Move resource form buttons to header
How can I move the submit/cancel and custom buttons of a resource form to another section of the page, e.g. together with the page header actions or above the form? If that is not possible, how can I call the form actions from a custom header actions, provided the actual action is hidden?
2 replies
FFilament
Created by tg on 1/25/2024 in #❓┊help
Must <foreign_model>_id be fillable to save it on resource creation?
I have two models, Opportunity -> belongsTo -> Company. The opportunities table has a company_id field which is * not nullable* to ensure data integrity. The Opportunity model has a relationship company.
class Opportunity extends Model
{
protected $fillable = [
// attributes of Opportunity, WITHOUT `company_id`
];

public function company(): BelongsTo
{
return $this->belongsTo(Company::class, 'company_id');
}
}
class Opportunity extends Model
{
protected $fillable = [
// attributes of Opportunity, WITHOUT `company_id`
];

public function company(): BelongsTo
{
return $this->belongsTo(Company::class, 'company_id');
}
}
Note that company_id is not included in $fillable, as other sections of my app outside the Filament admin panel should not be able to alter this relationship through requests. My OpportunityResource::form field for the relationship:
Forms\Components\Select::make('company_id')
->label('Company')
->relationship(name: 'company', titleAttribute: 'name')
->required(),
Forms\Components\Select::make('company_id')
->label('Company')
->relationship(name: 'company', titleAttribute: 'name')
->required(),
On the EditOpportunity page, I can alter the associated company just fine. On CreateOpportunity however, I can select a company but I get this error:
SQLSTATE[HY000]: General error: 1364 Field 'company_id' doesn't have a default value
SQLSTATE[HY000]: General error: 1364 Field 'company_id' doesn't have a default value
If I add company_id to Opportunity::$fillable, it works as expected. I'd expect consistent behavior between Create and Edit, so either require company_id in $fillable on both operations or on neither.
2 replies