Fileupload doesnt save original name in attachment_file_names

I have this action:
public function uploadAction(): Action
{
return Action::make('upload')
// ...
->form([
FileUpload::make('upload')
->disk(...)
->visibility('private')
->storeFileNamesIn('attachment_file_names')
->directory(...),
]);
}
public function uploadAction(): Action
{
return Action::make('upload')
// ...
->form([
FileUpload::make('upload')
->disk(...)
->visibility('private')
->storeFileNamesIn('attachment_file_names')
->directory(...),
]);
}
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 array
34 Replies
charlie
charlie2w ago
casting to array is for multiple files
Matthew
MatthewOP2w ago
I also tried uploading multiple Still nothing Update:
public function uploadAction(): Action
{
return Action::make('upload')
// ...
->form([
FileUpload::make('attachment')
->disk(config('filament-latex.storage'))
->unique()
->visibility('private')
->preserveFilenames()
->model($this->filamentLatex)
->directory($this->filamentLatex->id . '/files'),
]);
}
public function uploadAction(): Action
{
return Action::make('upload')
// ...
->form([
FileUpload::make('attachment')
->disk(config('filament-latex.storage'))
->unique()
->visibility('private')
->preserveFilenames()
->model($this->filamentLatex)
->directory($this->filamentLatex->id . '/files'),
]);
}
So i also tried adding the ->model() callable
charlie
charlie2w ago
if you don't have ->multiple(), you shouldn't cast to an array
Matthew
MatthewOP2w ago
I remvoed it in the example because I was trying something 😅 . But even with that, it still doesnt work
charlie
charlie2w ago
ok, I don't know, sorry
Matthew
MatthewOP2w ago
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
Takashi
Takashi2w ago
I think you should confirm that the database column attachment_file_names is defined as JSON in your migration, and also, the model
Dennis Koch
Dennis Koch7d ago
He stated exactly that
Matthew
MatthewOP5d ago
Any update on this?
Dennis Koch
Dennis Koch5d ago
I thought you figured it out here
Matthew
MatthewOP5d ago
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
awcodes
awcodes5d ago
What do you actually have in the ->action() callback?
Matthew
MatthewOP5d ago
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 security
awcodes
awcodes5d ago
Hmm, 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?
Matthew
MatthewOP5d ago
It doess, but they are not used:
TheThunderTurner\FilamentLatex\Models\FilamentLatex {#7547
id: 8,
name: "Test Document",
content: """
\documentclass{article}\n
\usepackage{graphicx}\n
\graphicspath{{../files/}}\n
\begin{document}\n
% Your content here\n
Hello World\\\n
This is a test\\\n
\includegraphics[width=0.5\textwidth]{test1.png}\n
\end{document}
""",
deadline: "2024-12-18 00:00:00",
author_id: 1,
collaborators_id: "["4","5","3","8","9","6"]",
attachment: null,
attachment_file_names: null,
created_at: "2024-12-16 00:56:04",
updated_at: "2024-12-17 15:35:34",
},
TheThunderTurner\FilamentLatex\Models\FilamentLatex {#7547
id: 8,
name: "Test Document",
content: """
\documentclass{article}\n
\usepackage{graphicx}\n
\graphicspath{{../files/}}\n
\begin{document}\n
% Your content here\n
Hello World\\\n
This is a test\\\n
\includegraphics[width=0.5\textwidth]{test1.png}\n
\end{document}
""",
deadline: "2024-12-18 00:00:00",
author_id: 1,
collaborators_id: "["4","5","3","8","9","6"]",
attachment: null,
attachment_file_names: null,
created_at: "2024-12-16 00:56:04",
updated_at: "2024-12-17 15:35:34",
},
Matthew
MatthewOP5d ago
The files are retrieved based on the files that are present in the specified directory
No description
awcodes
awcodes5d ago
Where are the files retrieved? I’m not seeing a relationship in that code. Are they even a relationship?
Matthew
MatthewOP5d ago
Nope. The files are retrieved like this:
public function getFiles(): array
{
return array_map('basename', $this->getStorage()->files($this->filamentLatex->id . '/files'));
}
public function getFiles(): array
{
return array_map('basename', $this->getStorage()->files($this->filamentLatex->id . '/files'));
}
Is this stupid? 🤣 . I find this to work really well But not in the upload action obviously. The action just stores them there
awcodes
awcodes5d ago
What is calling getFiles()
Matthew
MatthewOP5d ago
If youre really curious, you could have a look at my repo: hrere getFiles() is called here Basically in the view
awcodes
awcodes5d ago
Where is the FileUpload in the repo. Not seeing it at first glance?
awcodes
awcodes5d ago
Does it work if you change remove ->visibility(‘private’) Sorry, I’m trying to help, but I don’t actually know anything about latex. 😅
Matthew
MatthewOP5d ago
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)
awcodes
awcodes5d ago
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.
Matthew
MatthewOP5d ago
yeppp, thats true. In the config I have an option to set your filesystem. Mine looks like this:
'private' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'url' => env('APP_URL') . '/private_storage',
'visibility' => 'private',
'throw' => false,
],
'private' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'url' => env('APP_URL') . '/private_storage',
'visibility' => 'private',
'throw' => false,
],
Then I give a route here in getPdfUrl. Then the path in web.php is called, whcih calls the controller
awcodes
awcodes5d ago
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.🤔
awcodes
awcodes5d ago
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.
Matthew
MatthewOP5d ago
But why would that interfere with values being saved on the table? Because everything else is fine
awcodes
awcodes5d ago
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.
Matthew
MatthewOP5d ago
Ohhh, interesting... i didnt know that
awcodes
awcodes5d ago
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.
Matthew
MatthewOP4d ago
Yeahh hahaha Thanks for the help. I will check the paths later
Want results from more Discord servers?
Add your server