F
Filament13mo ago
riz

Can't use FileUpload with multiple

I have a resource form with FileUpload. FileUpload works fine with out using the "multiple". But when using multiple I get this error: Illuminate\Database\Grammar::parameterize(): Argument #1 ($values) must be of type array, int given, EMPLOYEE Model
protected $casts = [
'attachment_path' => 'array',
];

public function attachment() : HasOne
{
return $this->hasOne(Attachment::class, 'group_id');
}
protected $casts = [
'attachment_path' => 'array',
];

public function attachment() : HasOne
{
return $this->hasOne(Attachment::class, 'group_id');
}
Employee Resource
Forms\Components\Section::make()
->relationship(
'attachment',
condition: fn (?array $state): bool => filled($state['attachment_path']),
)
->schema([
Forms\Components\FileUpload::make('attachment_path')
->multiple()
->openable(),
])
Forms\Components\Section::make()
->relationship(
'attachment',
condition: fn (?array $state): bool => filled($state['attachment_path']),
)
->schema([
Forms\Components\FileUpload::make('attachment_path')
->multiple()
->openable(),
])
2 Replies
Tieme
Tieme13mo ago
Hi, You have multiple attachments but your model only hasOne Don't think below will solve the problem, but it is the first step
public function attachment() : hasMany
{
return $this->hasMany(Attachment::class, 'group_id');
}
public function attachment() : hasMany
{
return $this->hasMany(Attachment::class, 'group_id');
}
riz
rizOP13mo ago
if I use hasMany in the model I get this error. ERROR:
Filament\Forms\Components\Section::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\HasOne|Illuminate\Database\Eloquent\Relations\MorphOne|null, Illuminate\Database\Eloquent\Relations\HasMany returned
Filament\Forms\Components\Section::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\HasOne|Illuminate\Database\Eloquent\Relations\MorphOne|null, Illuminate\Database\Eloquent\Relations\HasMany returned
If I understand it correctly from this https://filamentphp.com/docs/3.x/forms/advanced#saving-data-to-relationships thats how I use the FileUpload inside the component Section with relationship. I thought hasOne will work, since multiple in FileUpload will store an array of multiple filename( in my case: attachment_path) in a column. I was expecting my database would store the record like this if I use ->multiple()
id group_id attachment_path
1 34 [file1.png, file2.png]
id group_id attachment_path
1 34 [file1.png, file2.png]
if I use hasMany in the model I get this error. ERROR:
Filament\Forms\Components\Section::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\HasOne|Illuminate\Database\Eloquent\Relations\MorphOne|null, Illuminate\Database\Eloquent\Relations\HasMany returned
Filament\Forms\Components\Section::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\HasOne|Illuminate\Database\Eloquent\Relations\MorphOne|null, Illuminate\Database\Eloquent\Relations\HasMany returned
If I understand it correctly from this https://filamentphp.com/docs/3.x/forms/advanced#saving-data-to-relationships thats how I use the FileUpload inside the component Section with relationship. I thought hasOne will work, since multiple in FileUpload will store an array of multiple filename( in my case: attachment_path) in a column. I was expecting my database would store the record like this if I use ->multiple()
id group_id attachment_path
1 34 [file1.png, file2.png]
id group_id attachment_path
1 34 [file1.png, file2.png]

Did you find this page helpful?