Edward van Tonder
Edward van Tonder
FFilament
Created by Edward van Tonder on 2/7/2025 in #❓┊help
Importing (and creating) data for more than one table
I'm trying to import data, but in the end I want to insert into more than one table. Problem details: - I have a users table. - I have a teachers table. - The import should add users to the users table but it should also create teachers (for new users) for each user Unless I understand the docs incorrectly, the ->relationship() helper won't work because I don't have existing teachers to match to users. My idea was to create teachers (and link them to a user) within the ->afterCreate() or ->afterSave() lifecycle hooks but this does not seem to work. In fact the hooks doesn't seem to fire at all. Currently I have:
public static function getColumns(): array
{
return [
ImportColumn::make('first_name')
->label('First Name')
->requiredMapping()
->rules(['required', 'string'])
->examples(['John', 'Jane'])
->exampleHeader('First Name'),

ImportColumn::make('last_name')
->label('Last Name')
->requiredMapping()
->rules(['required', 'string'])
->examples(['Doe', 'Mathews'])
->exampleHeader('Last Name'),

ImportColumn::make('email')
->label('Email Address')
->requiredMapping()
->rules(['required', 'email'])
->exampleHeader('Email Address'),
];
}
public static function getColumns(): array
{
return [
ImportColumn::make('first_name')
->label('First Name')
->requiredMapping()
->rules(['required', 'string'])
->examples(['John', 'Jane'])
->exampleHeader('First Name'),

ImportColumn::make('last_name')
->label('Last Name')
->requiredMapping()
->rules(['required', 'string'])
->examples(['Doe', 'Mathews'])
->exampleHeader('Last Name'),

ImportColumn::make('email')
->label('Email Address')
->requiredMapping()
->rules(['required', 'email'])
->exampleHeader('Email Address'),
];
}
public function resolveRecord(): ?User
{
return User::firstOrNew(['email' => $this->data['email']]);
}
public function resolveRecord(): ?User
{
return User::firstOrNew(['email' => $this->data['email']]);
}
protected function afterSave(): void
{
if (!$this->record->teacher) {
Teacher::create(['user_id' => $this->record->id]);
}
}
protected function afterSave(): void
{
if (!$this->record->teacher) {
Teacher::create(['user_id' => $this->record->id]);
}
}
Is there a better approach here? I'm I missing something? Any help would be appreciated.
2 replies
FFilament
Created by Edward van Tonder on 2/4/2025 in #❓┊help
Hide the "or sign up for an account/or sign in to your account" sections
I'm trying to hide the "or sign up for an account / or sign in to your account" sections on the Login / Register pages. I've searched both the docs and Discord without finding any solutions. I've tried using the provided registerAction() and loginAction() functions but these only allow you to manipulate the buttons themselves and not the "or" message part? Am I missing something super obvious?
public function registerAction(): Action
{
return Action::make('test')->extraAttributes([
'class' => 'hidden',
]);
}
public function registerAction(): Action
{
return Action::make('test')->extraAttributes([
'class' => 'hidden',
]);
}
4 replies