update user level according to the user ID

I have a problem when I want to change the data level, the problem is that the data level does not match the user ID

 public function updateLevel($level)
    {
        $checkuserToken = $this->users->where('level', $level)->first();
        if (count($checkuserToken) > 1) {
            if ($level == 'admin') {
                $data = [
                    'level' => 'superadmin',

                ];
                $activateUser = $this->users->update($checkuserToken, $data);
                if ($activateUser) {

                    return redirect()->to('/admin/admin');
                } else {
                    return redirect()->to('/admin/admin');
                }
                # code...
            } else {
                # code...
                $data = [
                    'level' => 'admin',

                ];
                $activateUser = $this->users->update($checkuserToken, $data);
                if ($activateUser) {
                    return redirect()->to('/admin/admin');
                } else {
                    return redirect()->to('/admin/admin');
                }
                # code...
            }
        } else {
            return redirect()->to('/admin/admin');
        }

this is my controller

<?= $this->extend('admin/template') ?>

<?= $this->section('content') ?>

<main class="col-md-9 ml-sm-auto col-lg-10 px-md-4 py-4">
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="/admin/admin">Admin</a></li>
            <li class="breadcrumb-item active" aria-current="page">Overview</li>
        </ol>
    </nav>
    <h1 class="h2">Admin</h1>

    <a href="<?= base_url('admin/addAdmin') ?>"><button type="button" class="btn btn-dark mt-3 mb-2">Add Data</button></a>
    <br>
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>No</th>
                <th>Nama</th>
                <th>Username</th>
                <th>Email</th>
                <th>Gambar</th>
                <th>Level</th>
                <th>delete</th>
            </tr>
        </thead>
        <tbody>
            <?php $no = 1; ?>
            <?php foreach ($admin as $r) : ?>
                <tr>
                    <td><?php echo $no++ ?></td>
                    <td><?php echo $r['nama'] ?></td>
                    <td><?php echo $r['username'] ?></td>
                    <td><?php echo $r['email'] ?></td>
                    <td><img src="<?= base_url('asset/upload/image/' . $r['image']) ?>" alt="" width="90" height="90" class="img-thumbnail"></td>
                    <td><a href="<?= base_url('/admin/level/'  . $r['level']) ?>"><?php echo $r['level'] ?></a></td>
                    <td><a href=""><button type="button" class="btn btn-danger">Hapus</button></a></td>
                </tr>
            <?php endforeach ?>
        </tbody>
    </table>
    <footer class="pt-5 d-flex justify-content-between">
        <span>Copyright © 2019-2020 <a href="https://themesberg.com">Themesberg</a></span>
        <ul class="nav m-0">
            <li class="nav-item">
                <a class="nav-link text-secondary" aria-current="page" href="#">Privacy Policy</a>
            </li>
            <li class="nav-item">
                <a class="nav-link text-secondary" href="#">Terms and conditions</a>
            </li>
            <li class="nav-item">
                <a class="nav-link text-secondary" href="#">Contact</a>
            </li>
        </ul>
    </footer>
</main>
<?= $this->endSection() ?>

this is my views

<?php

namespace AppModels;

use CodeIgniterModel;

class AdminModel extends Model
{
    protected $table            = 'admin';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $useSoftDeletes   = false;
    protected $protectFields    = true;
    protected $allowedFields    = ['nama', 'username', 'email', 'password', 'image', 'level', 'created_at'];

    protected bool $allowEmptyInserts = false;
    protected bool $updateOnlyChanged = true;

    protected array $casts = [];
    protected array $castHandlers = [];

    // Dates
    protected $useTimestamps = false;
    protected $dateFormat    = 'datetime';

    // Validation
    protected $validationRules      = [
        'nama' => 'required',
        'username' => 'required|max_length[254]|is_unique[admin.username,id,{id}]',
        'email'    => 'required|max_length[254]|valid_email',
        'password' => 'required|max_length[255]|min_length[8]',
        'image' => 'uploaded[image]|mime_in[image,image/jpg,image/jpeg,image/gif,image/png]|max_size[image,2048]'
    ];
    protected $validationMessages   = [];
    protected $skipValidation       = false;
    protected $cleanValidationRules = true;
}

this is my model

example
I want to change the data level with the user name tamaulanaa_
but that changes the data level with the user name udintod

what I expect is that if I change the data level it changes according to the user ID or username

what I expect is that if I change the data level it changes according to the user ID or username

New contributor

triahmad maulana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật