Bootstrap Modal仅显示最后一项的收集数据,而不是特定ID的数据

时间:2019-07-18 08:51:08

标签: laravel bootstrap-modal laravel-blade

我是laravel的新手。我有一种餐厅管理系统的仪表板。 我在刀片上显示菜单。通过从下拉列表中选择类别,其显示列表为Dishes。每个包含菜品Ingredients和菜品AddOn的菜品。现在,我在每个盘子的Ingredient上都具有“编辑”按钮,该按钮将针对特定盘子的Modal显示Ingredient。问题是,当我单击“ Modal Popup”编辑按钮时,它显示了“ Last Dish”的成分,而不是要编辑的“ Dish's Ingredient”。

@foreach($items as $item)
   <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
     <div class="menu-block">
        <div class="menu-content">
           <div class="row">
              <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
                 <div class="dish-img"><a href="#"><img height="120px" width="120px" src="{{asset($item['image'])}}" alt="" class="img-circle"></a></div>
                 </div>
                 <div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
                    <div class="dish-content">
                    <h5 class="dish-title">
            <a href="#"><b>{{$item['name']}}</b></a>
            <a href="{{route('edit.dish',$item['id'])}}" data-toggle="modal" data-target="#editdish"><i class="ft-edit"></i></a>
                        <a href="{{route('delete.dish',$item['id'])}}"><i class="ft-trash-2"></i></a>
            </h5>
                    <h6><b>Ingredients:</b></h6>
                      @foreach($add_ingredients as $add_ingredient)
                         @foreach($dish_ing as $dish_in)
                            @if($item['id']==$dish_in->dish_id&&$dish_in->ingredient_id==$add_ingredient['id'])
                               <span class="dish-meta" >/{{$add_ingredient['name']}}</span>
                            @endif
                         @endforeach
                      @endforeach
                      <a href="{{route('edit.ingredient',$item['id'])}}" data-toggle="modal" data-target="#editingredient"> <i class="ft-edit"></i>Edit</a>
                      <button type="button" class="btn" data-toggle="modal" data-target="#ingredient"><i class="ft-plus-square" ></i>Add</button>
                      <h6><b>Addons:</b></h6>
                         @foreach($add_items as $add_item)
                             @if($add_item['dish_id']==$item['id'])
                                 <span class="dish-meta" >/{{$add_item['name']}} </span>
                             @endif
                         @endforeach
                         <a href="" data-toggle="modal" data-target=".editaddon{{$item['id']}}"> <i class="ft-edit"></i>Edit</a>

Modal Section:

<div class="modal fade editaddon{{$item['id']}}" id="">
   <div class="modal-dialog">
      <div class="modal-content">
         <!-- Modal Header -->
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">×</button>
         </div>
         <!-- Modal body -->
         <div class="modal-body">
            <form class="form form-horizontal" method="get" action="">
            @csrf
            <div class="form-body">
               <h4 class="form-section"><i class="ft-user"></i>Dish Addon form</h4>
               <div class="form-group row">
                  <label class="col-md-3 label-control" for="projectinput6">Category Name</label>
                  <div class="col-md-9">
                     <select id="projectinput6" name="id2" class="form-control">
                         <option value="none" selected="" disabled="">Select Relevant Category</option>
                            @foreach($add_items as $add_item)
                               @if($add_item['dish_id']==$item['id'])
                                  <option value="{{$add_item['id']}}">{{$add_item['name']}}</option>
                               @endif
                            @endforeach
                     </select>
                   </div>
                </div>
             </div>
             </form>
          </div>
       </div>
    </div>
</div>

我只想在编辑时在模态中显示特定的菜式。 任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

我修改了代码段,并在主foreach循环中添加了模式框。我也从数据目标中删除了点。

 @foreach($items as $item)
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
    <div class="menu-block">
        <div class="menu-content">
            <div class="row">
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
                    <div class="dish-img"><a href="#"><img height="120px" width="120px" src="{{asset($item['image'])}}" alt="" class="img-circle"></a></div>
                </div>
                <div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
                    <div class="dish-content">
                        <h5 class="dish-title">
                            <a href="#"><b>{{$item['name']}}</b></a>
                            <a href="{{route('edit.dish',$item['id'])}}" data-toggle="modal" data-target="#editdish"><i class="ft-edit"></i></a>
                            <a href="{{route('delete.dish',$item['id'])}}"><i class="ft-trash-2"></i></a>
                        </h5>
                        <h6><b>Ingredients:</b></h6>
                        @foreach($add_ingredients as $add_ingredient)
                        @foreach($dish_ing as $dish_in)
                        @if($item['id']==$dish_in->dish_id&&$dish_in->ingredient_id==$add_ingredient['id'])
                        <span class="dish-meta">/{{$add_ingredient['name']}}</span>
                        @endif
                        @endforeach
                        @endforeach
                        <a href="{{route('edit.ingredient',$item['id'])}}" data-toggle="modal" data-target="#editingredient"> <i class="ft-edit"></i>Edit</a>
                        <button type="button" class="btn" data-toggle="modal" data-target="#ingredient"><i class="ft-plus-square"></i>Add</button>
                        <h6><b>Addons:</b></h6>
                        @foreach($add_items as $add_item)
                        @if($add_item['dish_id']==$item['id'])
                        <span class="dish-meta">/{{$add_item['name']}} </span>
                        @endif
                        @endforeach
                        <a href="" data-toggle="modal" data-target="editaddon-{{$item['id']}}"> <i class="ft-edit"></i>Edit</a>

                        <div class="modal fade editaddon-{{$item['id']}}" >
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <!-- Modal Header -->
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal">×</button>
                                    </div>
                                    <!-- Modal body -->
                                    <div class="modal-body">
                                        <form class="form form-horizontal" method="get" action="">
                                            @csrf
                                            <div class="form-body">
                                                <h4 class="form-section"><i class="ft-user"></i>Dish Addon form</h4>
                                                <div class="form-group row">
                                                    <label class="col-md-3 label-control" for="projectinput6">Category Name</label>
                                                    <div class="col-md-9">
                                                        <select id="projectinput6" name="id2" class="form-control">
                                                            <option value="none" selected="" disabled="">Select Relevant Category</option>
                                                            @foreach($add_items as $add_item)
                                                            @if($add_item['dish_id']==$item['id'])
                                                            <option value="{{$add_item['id']}}">{{$add_item['name']}}</option>
                                                            @endif
                                                            @endforeach
                                                        </select>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endforach