Fileupload doesnt save original name in attachment_file_names
I have this action:
But after successfully uploading the file, the record is null. I did set
attachment_file_names
as a json collumn in my migration, I added it in the $fillable array and its casting to array34 Replies
casting to array is for multiple files
I also tried uploading multiple
Still nothing
Update:
So i also tried adding the ->model() callable
if you don't have
->multiple()
, you shouldn't cast to an arrayI remvoed it in the example because I was trying something 😅 . But even with that, it still doesnt work
ok, I don't know, sorry
Ok, I need to create an ->action() and handle the record manipulation there
Its because I have added a form in a custom Filament Action outside of a standard form context.
https://filamentphp.com/docs/3.x/actions/modals#modal-forms
I think you should confirm that the database column attachment_file_names is defined as JSON in your migration, and also, the model
He stated exactly that
Any update on this?
I thought you figured it out here
no sorry, I forgot to reply to that. I couldnt get it to work :/. Unfortunately I dont have the code I wrote, but I can try recreating it
What do you actually have in the ->action() callback?
At the moment nothing, completely removed. This action function is for my latex plugin where you're supposed to upload files. The problem is, if you upload files without preserving the file names, then you cant give the original file name as input in
\includegraphics
for example. Im still not sure if its worth saving the original names in columns
The only reason why im even considering this is for securityHmm, I would still expect preserveFileNames to work. But since this is in a plug-in I don’t think you can depend on the user/dev to set it up appropriately.
Doesn’t you plugin have a model with a file column and a column for the filename?
It doess, but they are not used:
The files are retrieved based on the files that are present in the specified directory
Where are the files retrieved? I’m not seeing a relationship in that code.
Are they even a relationship?
Nope. The files are retrieved like this:
Is this stupid? 🤣 . I find this to work really well
But not in the upload action obviously. The action just stores them there
What is calling getFiles()
Where is the FileUpload in the repo. Not seeing it at first glance?
Does it work if you change remove ->visibility(‘private’)
Sorry, I’m trying to help, but I don’t actually know anything about latex. 😅
Ah itss okayy. The issue is more with FileUpload though. If you upload a document, it wont save its name in the column (of course we remove ->preserve() and we have the callback to store the original names in columns)
I ask about the visibility because I’m not seeing any route to resolve storage assets that aren’t public. When you set visibility to private you have to have a route to resolve them because in laravel those are expected to have verification on them, which storage:link won’t solve. So I’m wondering if the problem isn’t the persistence in the db but an http response.
I could be wrong but that’s what it’s looking like to me.
Honestly, though, if it is private and needs to be scoped to clients I wouldn’t even worry about filenames. I would let the defaults work and just let it use uuids for the file names.
Ok so theirs a trait for canUseDocument() but where is that url registered in the web routes? Sorry on my phone trying to follow as best I can.
The route file looks ok to me. Hmm.🤔
I’m thinking you have conflicting paths. GetPdfUrl() is using the panel id but your action is using latex id. ?
If that makes sense.?
I think the directories might be off with the disk.
But why would that interfere with values being saved on the table? Because everything else is fine
Because the value on the table is just a path from the storage route.
When filament reads out the value it uses the Storage facade to get the url.
So the directory etc. matters.
Ohhh, interesting... i didnt know that
You might need to utilize the hydration methods on the field to return the correct url. Not sure but a possibility depending on your app setup/disk config.
Disks can get very confusing. 😂
But it’s not necessarily a filament thing, but how disks and storage work in laravel.
Yeahh hahaha
Thanks for the help. I will check the paths later