Can I use a model in FileNameGeneratorInterface? #843
-
Hi, I can use a model's ID when generating the filename for an image that is uploaded so I can store it as 971.png for example? Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
karandatwani92
Feb 21, 2024
Replies: 1 comment 1 reply
-
Hey @klaaskox The file name is generated before saving. There is no model ID before saving. For other cases, You can create a custom FileNameGenerator and use it for naming files. If you want to name it model ID:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
klaaskox
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @klaaskox
The file name is generated before saving. There is no model ID before saving.
For other cases, You can create a custom FileNameGenerator and use it for naming files.
If you want to name it model ID:
$nextId = DB::table('user')->max('id') + 1;
in FileNameGenerator. (It's Bad practice.)