auto selecting company_id
Hello friends, please tell me how to make the attached screenshot so that instead of company_id, the current company is selected automotically (I have a multi tenancy implementation) Form code:
5 Replies
I'm just taking a stab at this. Does your model define the relationship between company contacts and the company?
On your CompanyContacts Model:
public function company(): BelongsTo
{
return $this->belongsTo(Company::class);
}
then I think you should be able to do:
Forms\Components\Select::make('company.name') and it will use the relationship ?
I've already done half the work, now I need the company name to be shown in the Company selection Field, not a void. 1 screenshot of the photo, as it should be. 2 screenshot like mine
Code:
Hello
To get the current company, you can do Filament::getTenant(), if company is your tenant of course
If it's always the current company, you can remove this field and mutate before save/create to add company id
like $data['company_id'] = Filament::getTenant()->id
plus if you are working with tenants, the company_id will automaticlly be set. you can maybe just remove it all.. (if your model Company has a hasmany relation with contacts that is)