Adocasts+

@ruslan-mr

Member Since
Nov 21, 2024
Lessons Completed
5
Comments Contributed
1
Hours Watched
0.77

Recent Activity

Here's what @ruslan-mr has been up to this past year

  • Completed lesson Creating A Layout

  • Commented on post Form Validation & Displaying Errors

    Hey! How can I send custom errors? I'm validating certFile and trying to return a response with response.unprocessableEntity, but I’m getting an error: "All Inertia requests must receive a valid Inertia response, but a plain JSON response was received." Any ideas?

      async store({ inertia, request, response }: HttpContext) {
        const data = await request.validateUsing(createPostCalendar)
        console.log('data', { data })
        const certFile = request.file('certFile', {
          size: '1mb',
          extnames: ['pfx'],
        })
    
        if (certFile) {
          if (!certFile.isValid) {
            // Not working, got error.
            return response.unprocessableEntity({
              errors: { certFile: certFile.errors },
            })
          }
          await certFile.move(app.makePath('storage/uploads'), {
            name: `${cuid()}.${certFile.extname}`,
          })
          Object.assign(data, { certFile: certFile.fileName })
        }
        await Calendar.create({ ...data })
        return response.redirect('/panel')
      }
    Copied!
  • Completed lesson The useForm Helper

  • Completed lesson Inertia Form Basics

  • Account created Welcome to Adocasts, @ruslan-mr!