file upload error

Does anyone has an issue with FileUpload form field? FIle is uploading as saved, but when I try to edit record with FileUplaod field I get an error: foreach() argument must be of type array|object, string given Laravel 11. Does anyone has a solution?
No description
14 Replies
LeandroFerreira
LeandroFerreira2mo ago
are you using ->multiple() ?
varovas
varovas2mo ago
No, I am using ->avatar
LeandroFerreira
LeandroFerreira2mo ago
could you share the code?
varovas
varovas2mo ago
FileUpload::make('avatar')
->label(__('Image'))
->columnSpanFull()
->visible(fn(Get $get): bool => !empty($get('../is_customer')))
->avatar()
->disk('local')
->directory('avatars')
->visibility('public')
FileUpload::make('avatar')
->label(__('Image'))
->columnSpanFull()
->visible(fn(Get $get): bool => !empty($get('../is_customer')))
->avatar()
->disk('local')
->directory('avatars')
->visibility('public')
LeandroFerreira
LeandroFerreira2mo ago
what happens if you change ->disk('public') ?
varovas
varovas2mo ago
Same 😦
LeandroFerreira
LeandroFerreira2mo ago
are you using the panel builder or only the form builder?
varovas
varovas2mo ago
I assume $this->getState() return value from database, and not array. Good question. I am not very familiar with exact term, but I am building form in form method in UserResource.
LeandroFerreira
LeandroFerreira2mo ago
Did you create a UserResource, right? And add the avatar column as a string column in the users table?
varovas
varovas2mo ago
technically avatar is in profiles table column. But yes, avatar column is string
LeandroFerreira
LeandroFerreira2mo ago
Is profile a relationship?
varovas
varovas2mo ago
yes
LeandroFerreira
LeandroFerreira2mo ago
try
Group::make([
FileUpload::make('avatar')
->avatar()
->disk('public')
->directory('avatars'),
])
->relationship('profile')
Group::make([
FileUpload::make('avatar')
->avatar()
->disk('public')
->directory('avatars'),
])
->relationship('profile')
varovas
varovas2mo ago
I made similar with fieldset. Filename is saved to profiles table. The issue is I think, that when retrieving file it expects array, but state has path string
Want results from more Discord servers?
Add your server