jeudi 25 novembre 2021

Multi attribute of products (guaranteree table) in Laravel in which not created multiple index (array)

Please tell me error when I add multi attribute (array) of member it take only first of arrray[0] and not increases index number Please tell in where I problem in this code. Anyone know the problem?

It is controller code manage_members_list:

public function manage_members_list($id='')
{
    if ($id > 0) {
        $arr = Members_list::where(['id' => $id])->get();
        $result['id'] = $arr[0]->id;
        $result['name'] = $arr['0']->name;
        $result['father_name'] = $arr['0']->father_name;
        $result['email'] = $arr['0']->email;
        $result['mobile'] = $arr['0']->mobile;
        $result['phone'] = $arr['0']->phone;
        $result['cnic'] = $arr['0']->cnic;
        $result['city'] = $arr['0']->city;
        $result['area'] = $arr['0']->area;
        $result["member_gruntee"] = Garuanter::where(['member_id' => $id])->get();

    } else {
        $result['name'] = '';
        $result['father_name'] = '';
        $result['email'] = '';
        $result['mobile'] = '';
        $result['phone'] = '';
        $result['cnic'] = '';
        $result['id'] = 0;
        $result['city'] = '';
        $result['area'] = '';

        $result['member_gruntee'][0]['id'] = 0;
        $result['member_gruntee'][0]['gname'] = '';
        $result['member_gruntee'][0]['gaddress'] = '';
        $result['member_gruntee'][0]['gcnic'] = '';
        $result['member_gruntee'][0]['gphone'] = '';
    }
    $result['city_list'] = City::all();
    return view('manage_members_list', $result);
}

Blade Template Data is here:

<div class="row" style="margin-top: 10px;">
            <div class="col-sm-12 right_contents content_right">
                <div class="inner_contents table-responsive customers_setup">
                    <div class="main_head">
                        <h4>Gauranters</h4>
                    </div>

                        @php
                            $loop_count_num = 1;
                            $loop_count_prev = $loop_count_num;
                        @endphp
                        @foreach ($member_gruntee as $key)
                            @php
                                $loop_count_prev = $loop_count_num;
                            @endphp
                            <div class="member_gruantee">
                            <input type="hidden" id="mmd" name="mmd[]" value="">
                            <div class="form-group">
                                <div id="member_attr_">

                                <div class="row">

                                    <div class="col-sm-2 padd_right">
                                        <div class="input_label_box">
                                            <label>Name*</label>
                                            <input type="text" placeholder="" id="gname" name="gname[]"
                                                value="">
                                        </div>
                                    </div>
                                    <div class="col-sm-2 padd_right">
                                        <div class="input_label_box">
                                            <label>Phone</label>
                                            <input type="text" id="gphone" placeholder="" name="gphone[]"
                                                value="">
                                        </div>
                                    </div>
                                    <div class="col-sm-2 padd_right">
                                        <div class="input_label_box">
                                            <label>CNIC</label>
                                            <input type="text" id="gcnic" name="gcnic[]" value="">
                                        </div>
                                    </div>
                                    <div class="col-sm-5">
                                        <div class="input_label_box">
                                            <label>Address</label>
                                            <input type="text" id="gaddress" name="gaddress[]" value="">
                                        </div>
                                    </div>
                                    @if ($loop_count_num == 2)
                                        <div class="col-sm-1">
                                            <div class="plus_btn">
                                                <a type="submit" onclick="add_more()" id="Add"><i
                                                        class="fa fa-plus"></i></a>
                                            </div>
                                        </div>
                                    @else
                                        <div class="col-sm-1">
                                            <div class="minus_btn">
                                                <a href="//"
                                                    onclick="remove_more('')" id="Remove"><i
                                                        class="fa fa-minus"></i></a>
                                            </div>
                                        </div>
                                    @endif
                                </div>
                        @endforeach
                    </div>
                </div>
               </div>
            </div>

    

JQuery Function is here:

var loop_count = 1;

function add_more() {
    loop_count++;
    var html =
        '<input type="hidden" id="mmd" name="mmd[]"><div class="form-group"><div id="member_attr_'+loop_count +'"><div class="row">';
    html +=
        '<div class="col-sm-2 padd_right"><div class="input_label_box"><label>Name*</label><input type="text" name="gname[]" id="gname" placeholder="" ></div></div>';
    html +=
        '<div class="col-sm-2 padd_right"><div class="input_label_box"><label>Phone</label><input type="text" name="gphone[]" id="gphone" placeholder=""></div></div>';
    html +=
        '<div class="col-sm-2 padd_right"><div class="input_label_box"><label>CNIC</label><input type="text" name="gcnic[]" id="gcnic"></div></div>';
    html +=
        '<div class="col-sm-5"><div class="input_label_box"><label>Address</label><input type="text" id="gcnic" name="gaddress[]"></div></div>';
    html += '<div class="col-sm-1"><div class="minus_btn"><a onclick=remove_more("' + loop_count +
        '") id="Remove"><i class="fa fa-minus"></i></a></div></div></div></div></div>';
         $('.member_gruantee').append(html);
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire