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