You need to override the resolveRecord() method in your Filament Importer class. Since you're dealing with two tables, handle the User creation first, extract the resulting ID, and then return the associated Teacher instance.
Using firstOrCreate for the user and firstOrNew for the teacher perfectly handles your "not existing records" requirement without throwing duplication errors.
use App\Models\User;
use App\Models\Teacher;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
protected function resolveRecord(): ?Model
{
$user = User::firstOrCreate(
['email' => $this->data['email']],
[
'name' => $this->data['name'],
'password' => bcrypt($this->data['password'] ?? Str::random(12)),
]
);
return Teacher::firstOrNew(
['employee_number' => $this->data['employee_number']],
[
'user_id' => $user->id,
'slug' => $this->data['slug'] ?? Str::slug($this->data['name']),
'hire_date' => $this->data['hire_date'],
]
);
}
Just ensure your importer's getColumns() method includes the definitions for name, email, and password, even though they belong to the users table. Filament will load them into $this->data so you can intercept them here.