F
Filament9mo ago
afdhal

Import Action Relation with OptionForm

:cool_tofu: :squint: How to import CSV data using getOptionsFormComponents, For example, I want to import student data, for school_id I select it via the form, please help me where the error is. studentImporter :
public static function getOptionsFormComponents(): array
{
return [
Select::make('school_id')
->relationship('school', 'name')
->searchable()
->required()
->preload(),

];
}
public static function getOptionsFormComponents(): array
{
return [
Select::make('school_id')
->relationship('school', 'name')
->searchable()
->required()
->preload(),

];
}
resolveRecord
public function resolveRecord(): ?Siswa
{
if ($this->options['school_id'] ?? false) {
return Sekolah::firstOrNew([
'school_id' => $this->data['school_id'],
]);
}

return new Siswa();
}
public function resolveRecord(): ?Siswa
{
if ($this->options['school_id'] ?? false) {
return Sekolah::firstOrNew([
'school_id' => $this->data['school_id'],
]);
}

return new Siswa();
}
erros:
Undefined array key "school_id"
Undefined array key "school_id"
No description
3 Replies
afdhal
afdhalOP9mo ago
:fi: please help Solution
⁠ return new Siswa([
'school_id' => $this->options['school_id'],
]); ⁠
⁠ return new Siswa([
'school_id' => $this->options['school_id'],
]); ⁠
Jellibloom
Jellibloom9mo ago
Thanks for sharing the solution I was trying to it like below but was getting error
$this->data['city_id'] = $this->options['city_id'];
return new Area();
$this->data['city_id'] = $this->options['city_id'];
return new Area();
afdhal
afdhalOP9mo ago
public function resolveRecord(): ?Siswa
{

$siswa = Siswa::query()
->where('nisn', $this->data['nisn'])
->first();

if (! $siswa) {
$siswa = new Siswa([
'sekolah_id' => $this->options['sekolah_id'],
'periode_id' => $this->options['periode_id'],
'cetak_kartu' => $this->options['cetak_kartu'] ? 1 : 0,
]);
}

return $siswa;
}
public function resolveRecord(): ?Siswa
{

$siswa = Siswa::query()
->where('nisn', $this->data['nisn'])
->first();

if (! $siswa) {
$siswa = new Siswa([
'sekolah_id' => $this->options['sekolah_id'],
'periode_id' => $this->options['periode_id'],
'cetak_kartu' => $this->options['cetak_kartu'] ? 1 : 0,
]);
}

return $siswa;
}
Want results from more Discord servers?
Add your server