在laravel中以模态显示数据

时间:2018-04-30 16:24:26

标签: php laravel materialize

我正在使用Laravel,我正在尝试删除或更新平台上的服务 我正在使用确认模式... 但是当我删除或更新或显示模态中的内容时,它总是仅在第一行...

这就是代码

@foreach ($services as $service)
    <div class="card-content">
        <div class="row">
            <div class="col l4">

                <div class="row">
                    <div class="col s12">
                        <span>
                            <a class="btn-floating btn-large modal-trigger tooltipped waves-effect waves-light red hoverable" 
                               data-position="left" 
                               data-tooltip="Supprimer ce service"
                               data-text-color="grey-text"
                               href="#modal1">
                                <i class="material-icons">delete</i>
                            </a>
                        </span>

                        <span>  
                            <a class="btn-floating btn-large modal-trigger tooltipped waves-effect waves-light green" 
                               data-position="right" 
                               data-tooltip="Modifier ce service" 
                               data-delay="20" 
                               href="#modal2">
                                <i class="material-icons" href="#modal2">update</i>
                            </a>
                        </span>
                    </div>
                </div>

                <div id="modal1" class="modal">
                    <div class="modal-content">
                        <div class="row">
                            <div class="col s6">
                                <p>Voulez vous vraiment supprimer ce service ?</p> 
                            </div>

                            <div class="col s6">
                                <form action="/Services/{{$service->id}}" method="POST">
                                    {{ csrf_field() }}
                                    @method('DELETE')

                                    <span>   
                                        <input type="submit" class="btn purple hoverable waves effect" value="supprimer">
                                    </span>

                                    <span>    
                                        <a href="#" class="btn red hoverable waves effect modal-action modal-close" id="non"> Non</a>
                                    </span>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
@endforeach

2 个答案:

答案 0 :(得分:0)

通过jquery调用模态,如

$('#myModal').modal('show');
$('#myModal').modal('hide');

In Loop Anchor

    <span>  
                                <a class="btn-floating btn-large modal-trigger tooltipped waves-effect waves-light green modalclick" 
                                   data-position="right" 
                                   data-tooltip="Modifier ce service" 
                                   data-delay="20" 
                                   data-id="<?php echo $service->id; ?>"
                                   href="javascript:void(0)"

>
                                    <i class="material-icons" href="#modal2>update</i>
                                </a>
                            </span>



$(".modalclick").click(function(){
   var current_id = $(this).attr("data-id");

   //use jquery below to change modal form action with id
$('#myModal').modal('show');

});

答案 1 :(得分:0)

如果你在循环中,如果你不想使用获取和服务id的jquery并传入模态形式,则为每条记录定义模态弹出窗口。

<?php $a = 1; ?>
@foreach ($services as $service)
    <div class="card-content">
        <div class="row">
            <div class="col l4">

                <div class="row">
                    <div class="col s12">
                         <span>  <a class="btn-floating btn-large modal-trigger tooltipped waves-effect waves-light red hoverable" data-position="left" data-tooltip="Supprimer ce service" data-text-color="grey-text" href="#modal{{$a}}"><i class="material-icons">delete</i></a></span>
                         <span>  <a  class="btn-floating btn-large modal-trigger tooltipped waves-effect waves-light green" data-position="right" data-tooltip="Modifier ce service"  data-delay="20" href="#modal2"><i class="material-icons" href="#modal2">update</i></a></span>
                    </div>
                </div>
                <div id="modal{{$a}}" class="modal">
                    <div class="modal-content">
                        <div class="row">
                            <div class="col s6">
                                <p>Voulez vous vraiment supprimer ce service ?</p> 
                            </div>

                            <div class="col s6">
                                <form action="/Services/{{$service->id}}" method="POST">
                                    {{ csrf_field() }}
                                    @method('DELETE')
                                    <span>
                                        <input type="submit" class="btn purple hoverable waves effect" value="supprimer">
                                    </span>
                                    <span>
                                        <a href="#" class="btn red hoverable waves effect modal-action modal-close" id="non"> Non</a>
                                    </span>
                                </form>
                            </div>
                        </div>
                    </div>
               </div>
           </div>
       </div>
    </div>
    <?php $a++; ?>
@endforeach

看看它是否适合你。