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 } =;
        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.',
            '': '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()) {
            return response.redirect('back')
        } = request.input('name'); = request.input('email');
        student.password = await Hash.make(request.input('password'));

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

And I have also added hidden field for id inside form

<input type="hidden" value="{{}}">

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

instead of

const { userid } =


const { userid } =;

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="{{}}" name="id">. It worked for me.

Why didn’t work for me because i have searched for it and has worked for others. What does do?