Skip to content
Discussion options

You must be logged in to vote

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:

  • You can do it in alternative ways of course, for example, you can write your upload function that first saves the model, gets the ID, then saves the file with the ID, and updates the model value. The guide to override the store method is here.
  • Alternatively, It's recommended to use media library uploaders to link uploaded media to a model.
  • Some would put $nextId = DB::table('user')->max('id') + 1; in FileNameGenerator. (It's Bad practice.)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@klaaskox
Comment options

Answer selected by klaaskox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants