F
Filament4mo 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
afdhal4mo ago
:fi: please help Solution
⁠ return new Siswa([
'school_id' => $this->options['school_id'],
]); ⁠
⁠ return new Siswa([
'school_id' => $this->options['school_id'],
]); ⁠
Jellibloom
Jellibloom3mo 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
afdhal3mo 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
More Posts
Filter widgethttps://discord.com/channels/883083792112300104/1212957406103994430Unable to set the width of the color picker in formThis: ``` ->type('color') ->extraInputAttributes(['width' => 100]) ``` Doesn't seem to be working.Building my first table action and it's doing weird behaviour using Spatie Tags plugin.I have a table on my resource that I'm adding a `manage tags` action to. This is using the filament Getting a 419 error when trying to download exportI wanted to give exporting a try so I ran the necessary migrations and created a very simple export.Using Plugin Auto Panel How to Colorize Table Rows Conditionallythe uplugin gives us this func to overide the columns and forms and infolist : public static functwrite test for validating fields on the custom form componentI have a custom filament form component with two fields, prompt and SKU, I want to write a test suitIs it possible to extend RichEditor?How would I start extending the RichEditor - to add a couple of new buttons, such alignment for examRadio button layout based on media breakpoint?Is it possible to have ->inline() at larger screen sizes but not on small ones? The options wrap finOn Selects is it possible to make the createOptionForm button clearerOn `Selects` is it possible to make the `createOptionForm` button clearer or have it as a standalonedisable single bulk action if one of the records is not applicableI am trying to conditionally show/hide bulk actions (per action) so that if the user selected some r