FileUpload on relation ( HasOne) extra parameters

Hello, I have a case where the i have a file() relation to another File entity, and that file entity has some extra fields required Any way i can pass those extra fields values need, when I save my form?
3 Replies
jamesro
jamesro3w ago
What am I doing wrong here? why is filament trying to save my second upload field relation even if I don't selected a file in that field?
Fieldset::make('Adaugati un fisier')
->relationship('fisierAditional')
->mutateRelationshipDataBeforeCreateUsing(function ($data, Set $set, Get $get){
$data['user_add'] = auth()->id();
$data['data_add'] = now();
$data['tip'] = 1;

return $data;
})
->schema([
FileUpload::make('fisier_aditional')
->hiddenLabel()
->downloadable()
->columnSpan('full')
->directory('pdfs/comenzi')
->visibility('public')
->placeholder('Numai imagini sau fisiere de tip PDF.')
->acceptedFileTypes(['application/pdf', 'image/*']),
]),
Fieldset::make('Adaugati un fisier')
->relationship('fisierAditional')
->mutateRelationshipDataBeforeCreateUsing(function ($data, Set $set, Get $get){
$data['user_add'] = auth()->id();
$data['data_add'] = now();
$data['tip'] = 1;

return $data;
})
->schema([
FileUpload::make('fisier_aditional')
->hiddenLabel()
->downloadable()
->columnSpan('full')
->directory('pdfs/comenzi')
->visibility('public')
->placeholder('Numai imagini sau fisiere de tip PDF.')
->acceptedFileTypes(['application/pdf', 'image/*']),
]),
Fieldset::make('Adaugati un email')
->relationship('fisierEmail')
->mutateRelationshipDataBeforeCreateUsing(function ($data, Set $set, Get $get){
//if($data['fisier_aditional'] !== null) {
$data['user_add'] = auth()->id();
$data['data_add'] = now();
$data['tip'] = 2;
//}
return $data;
})
->schema([
FileUpload::make('fisier_aditional')
->acceptedFileTypes(['application/vnd.ms-outlook'])
->hiddenLabel()
->downloadable()
->columnSpan('full')
->directory('emails/comenzi')
->visibility('public')
->placeholder('Numai fisiere cu extensia .msg')
]),
Fieldset::make('Adaugati un email')
->relationship('fisierEmail')
->mutateRelationshipDataBeforeCreateUsing(function ($data, Set $set, Get $get){
//if($data['fisier_aditional'] !== null) {
$data['user_add'] = auth()->id();
$data['data_add'] = now();
$data['tip'] = 2;
//}
return $data;
})
->schema([
FileUpload::make('fisier_aditional')
->acceptedFileTypes(['application/vnd.ms-outlook'])
->hiddenLabel()
->downloadable()
->columnSpan('full')
->directory('emails/comenzi')
->visibility('public')
->placeholder('Numai fisiere cu extensia .msg')
]),
I'm expecting it to create the second relation only if I selected a file on that second field @Dan Harrin any suggestion?
Carl-bot
Carl-bot3w ago
jamesro5976 has been warned, this is their first warning.
toeknee
toeknee3w ago
You shouldn't really be doing that level of mutation. You can add them to the model's booted method on static::creating?
Want results from more Discord servers?
Add your server