Skip to content

Instantly share code, notes, and snippets.

@diego3g
Created July 17, 2018 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diego3g/66416eb5556529067872d847157e9f23 to your computer and use it in GitHub Desktop.
Save diego3g/66416eb5556529067872d847157e9f23 to your computer and use it in GitHub Desktop.
async store ({ params, request }) {
const property = await Property.findOrFail(params.id)
const images = request.file('image', {
types: ['image'],
size: '2mb'
})
await images.moveAll(Helpers.tmpPath('uploads'), file => ({
name: `${Date.now()}-${file.clientName}`
}))
if (!images.movedAll()) {
return images.errors()
}
await Promise.all(
images
.movedList()
.map(image => property.images().create({ path: image.fileName }))
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment