未定义的偏移量:1- Laravel Error异常

I Know there are several links referred to this error but still I am unable to find the exact solution of my issue. I have two check-boxes named admin_menu_id[] and admin_sub_menu_id[] whose value i want to insert into database. So far I have done this:-

View page

 @if(is_array($roledatas) && count($roledatas)>0)
    <?php $count = 1;?>
    @foreach($roledatas as $roleKey=>$roleVal)
        <ul id="package_{{ $count }}" class="accordion-toggle parentclasstr" data-toggle="collapse" data-parent="#OrderPackages" data-target=".packageDetails{{ $count }}">

            <li><input type="checkbox" id="menuChk" value= "<?php echo $id = $roleVal['id']; ?>" name="admin_menu_id[]" /><strong>{{ $roleVal['name'] }}</strong></li>
            <li><i class="indicator glyphicon glyphicon-chevron-up pull-right"></i></li>                        

        @if(isset($roleVal['child']) && is_array($roleVal['child']) && count($roleVal['child'])>0)
            @foreach($roleVal['child'] as $childKey=>$childVal)
        <ul class="hiddenRow collapse packageDetails{{ $count }}" bgcolor="#C1C1C1">

            <li><input type="checkbox" id="submenuChk" value="<?php echo $id = $childVal['id']; ?>" name="admin_sub_menu_id[]" />{{ $childVal['name'] }}</li>
            <li></li>
        </ul>
            @endforeach
        @endif
        </ul>
        <?php $count++; ?>
    @endforeach
@endif

Controller:-

$data = $request->all();
    $user_type_id = $data['user_type_id'];
    $admin_menu_id = $data['admin_menu_id'];
    $admin_sub_menu_id = $data['admin_sub_menu_id'];

    for ($i = 0; $i < count($data['admin_sub_menu_id']); $i++)
    {
        $role = new RoleMenu;
        $role->user_type_id = $user_type_id;
        $role->admin_menu_id = $admin_menu_id[$i];
        $role->admin_sub_menu_id = $admin_sub_menu_id[$i];
        $role->save();
    }

It inserts data when i check one admin_menu_id checkbox and one admin_sub_menu_id checkbox but when try to check more than one it throws an error of Undefined Offset. I am completely new to laravel and these array games!! Kindly help me out on this.

The loop in your controller goes from 0 to count($data['admin_sub_menu_id']), are you sure the number of $admin_menu_id submitted corresponds to count($data['admin_sub_menu_id'])? If not, you will always get that error.

I suggest you have 2 loops, the outer loop to control admin_menu_id and the inner loop to control the admin_sub_menu_id!!