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
LeandroFerreira4mo ago
are you using ->multiple() ?
varovas
varovasOP4mo ago
No, I am using ->avatar
LeandroFerreira
LeandroFerreira4mo ago
could you share the code?
varovas
varovasOP4mo 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
LeandroFerreira4mo ago
what happens if you change ->disk('public') ?
varovas
varovasOP4mo ago
Same 😦
LeandroFerreira
LeandroFerreira4mo ago
are you using the panel builder or only the form builder?
varovas
varovasOP4mo 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
LeandroFerreira4mo ago
Did you create a UserResource, right? And add the avatar column as a string column in the users table?
varovas
varovasOP4mo ago
technically avatar is in profiles table column. But yes, avatar column is string
LeandroFerreira
LeandroFerreira4mo ago
Is profile a relationship?
varovas
varovasOP4mo ago
yes
LeandroFerreira
LeandroFerreira4mo 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
varovasOP4mo 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