F
Filamentβ€’8mo ago
Jamie Cee

FileUpload Not storing to DB

I've setup a file upload called 'avatar', the image seems to upload fine as inside my docker container, inside my path in storage/ I can view (although it saves as a .webp extension instead of the .jpg I uploaded? But the url should store into my DB correct? It wont save and not sure what im missing.
Forms\Components\FileUpload::make('avatar')
->image()
->disk('local')
->directory('offers'),
Forms\Components\FileUpload::make('avatar')
->image()
->disk('local')
->directory('offers'),
14 Replies
einnlleinhatt_
einnlleinhatt_β€’8mo ago
Did you make the avatar fillable in the model ?
Jamie Cee
Jamie Ceeβ€’8mo ago
That may actually be a fair point... bare with I forgot, its always the simple things 🀣 Just now need a way to store the full URL rather than just the path/filename
einnlleinhatt_
einnlleinhatt_β€’8mo ago
This is so true 🫠
Jamie Cee
Jamie Ceeβ€’8mo ago
Friday brain is kicking in
"http:\/\/localhost:8080\/storageoffers\/01HG0FBHXT0PVF1MCFVZB6E47G.png"
"http:\/\/localhost:8080\/storageoffers\/01HG0FBHXT0PVF1MCFVZB6E47G.png"
The image stores like this for some reason, is there a way to strip the tags so it stores as
http://localhost:8080/storage/offers/image.png
http://localhost:8080/storage/offers/image.png
Want to remove the " and the \ slashes
einnlleinhatt_
einnlleinhatt_β€’8mo ago
I'm not sure about that, maybe some config on the drive? Or docker things squint
Jamie Cee
Jamie Ceeβ€’8mo ago
Idk if its some encoding done by the file upload process. Just tryna trace through the codebase
einnlleinhatt_
einnlleinhatt_β€’8mo ago
Good luck πŸ€
Jamie Cee
Jamie Ceeβ€’8mo ago
Found it, I was dumb For context, when I was following the docs, I had avatar cast as an array, which was causing the URL issue Actually want to re-open this. When using the FileUpload. On the edit page, should the image be pre-populated? As based on my custom logic, a null value will remove the image, as I want the option for a user to be able to remove an image, but also keep the same one if its unchanged I get no preview when I go to edit a record, so not sure if its supposed to?
einnlleinhatt_
einnlleinhatt_β€’8mo ago
@Jamie Cee how about the app url in your env file? In my case when I edit something with an image, the old one will be previewed and I can remove it.
Jamie Cee
Jamie Ceeβ€’8mo ago
Set to http://localhost at the moment as im developing locally
einnlleinhatt_
einnlleinhatt_β€’8mo ago
I usually change it to the url I access, since I'm using laragon I change it to mydomain.test
Jamie Cee
Jamie Ceeβ€’8mo ago
Oh I changed it from localhost to
APP_URL=http://127.0.0.1:8080
APP_URL=http://127.0.0.1:8080
einnlleinhatt_
einnlleinhatt_β€’8mo ago
Try edit and see what's the path for the image.
Jamie Cee
Jamie Ceeβ€’8mo ago
But then thats gonna supply a URL to something that doesn't exist, no? It shows correctly in the table view:
Tables\Columns\ImageColumn::make('avatar')
->circular(),
Tables\Columns\ImageColumn::make('avatar')
->circular(),
Just not in the upload block in the form
Want results from more Discord servers?
Add your server
More Posts