How to import belongsToMany fields in the filament importer?

public static function getColumns(): array
    {
        return [
            ImportColumn::make('first_name')
                ->requiredMapping()
                ->rules(['required', 'max:255'])
                ->example('John'),
            ImportColumn::make('last_name')
                ->requiredMapping()
                ->rules(['required', 'max:255'])
                ->example('Doe'),
            ImportColumn::make('email')
                ->requiredMapping()
                ->rules(['required', 'email', 'max:255'])
                ->example('john@example.com'),
            // ImportColumn::make('company_name')
            //     ->relationship('companies', 'name')
            //     ->rules(['required', 'max:255', 'exists:mvl_companies,name'])
            //     ->example('Best Cycles Inc.'),
            // ImportColumn::make('company_employee_id')
            //     ->rules(['required', 'max:255'])
            //     ->example('BCI-123'),
            // ImportColumn::make('company_employee_budget')
            //     ->numeric()
            //     ->rules(['required'])
            //     ->example('10.00,23')
        ];
    }


 public function resolveRecord(): ?User
    {
        return User::firstOrNew([
            'email' => $this->data['email'],
        ]);
    }


The getColumns() has the 3 users table fields on the top followed by the related user_company (pivot table) fields i.e. company_employee_id and company_employee_budget allong with the company name from the companies table commented out.
How to I ensure that I am able to add a user and then find the company by name and attach that company with the newly inserted or updated user?
Was this page helpful?