How to update unique field in adonis js

If a user update their profile and doesn’t change email, the unique validator say the email is already taken. How to use unique but ignore for users own profile?

My controller:

async update({params, request, response, session}) {
        const { userid } = this.ctx.request.post();
        const rules = {
            name: 'required',
            email: `required|email|unique:students,email,id,${userid}`,
            // email: 'required|email|unique:students,email',
            password: 'required'
        };
        const messages = {
            'name.required': 'Name is required.',
            'email.required': 'You must provide a email address.',
            'email.email': 'You must provide a valid email address.',
            'email.unique': 'This email is already taken.',
            'password.required': 'You must provide a password'
        };
        const validation = await validate(request.all()));
        if (validation.fails()) {
            session
                .withErrors(validation.messages())
                .flashExcept(['password']);
            return response.redirect('back')
        }
        student.name = request.input('name');
        student.email = request.input('email');
        student.password = await Hash.make(request.input('password'));
        
        await student.save();

        session.flash({notification: 'Student updated'});
        return response.redirect('/students')
    }

And I have also added hidden field for id inside form

<input type="hidden" value="{{student.id}}">

I get the this error: Cannot read property ‘request’ of undefined.

instead of

const { userid } = this.ctx.request.post()

use

const { userid } = request.post();

Still it gives me unique validation failed for email

I solved my problem using let userid = request.input(‘id’) and getting id from my form as <input type="hidden" value="{{student.id}}" name="id">. It worked for me.

Why this.ctx.request.post() didn’t work for me because i have searched for it and this.ctx.request.post() has worked for others. What does this.ctx.request.post do?