如何从一行获取数据并转移到模态?Laravel 5.4

Vin*_*ius 2 php laravel laravel-5

我有一个表格,其中包含我的数据库中的listo产品,其中包含ID,名称,描述以及其他数据类型.我创建了一个按钮,可以调用模态来显示有关产品的更多详细信息,但是模式始终显示表中第一个产品的详细信息,而不是与其相关的ID.

我的桌子:

在此输入图像描述

我的表格代码:

    <table class="table table-striped table-bordered" id="table1" class="table table-bordered">
                                <thread>
                                    <th><center>Imagem</center></th>
                                    <th>SKU</th>
                                    <th><center>Produto</center></th>
                                    <th>Custo</th>
                                    <th>Preço</th>
                                    <th>Atualização</th>
                                    <th>Status</th>
                                    <th>Estoque</th>
                                    <th>Distruibuidor</th>
                                    <th>Categoria</th>
                                    <th id="acoes">Ações</th>
                                </thread>
                                @foreach($product as $prod)
                                    <thread>
                                        <tbody>
                                        <td><img src="{{$prod->image->erp_image}}" style="width: 50px; height: 50px;" alt="" id="ProdImage"></td>
                                        <td>{{$prod->erp_model}}</td>
                                        <td>{{$prod->description->erp_name}}</td>
                                        <td>R$ {{$prod->erp_cost}}</td>
                                        <td>R$ {{$prod->erp_price}}</td>
                                        <td>{{ $prod->erp_modifieddate}}</td>
                                        <td style="max-width: 45px">
                                            @if($prod->status == 1)
                                                <span class="label label-success">Ativo</span>
                                            @else
                                                <span class="label label-danger">Inativo</span>
                                            @endif
                                        </td>
                                        <td>{{ $prod->erp_quantity}}</td>
                                        <td>@if($prod->erp_distributor == 'A')
                                                <span class="label label-default">Aldo</span>
                                            @elseif($prod->erp_distributor == 'AN')
                                                <span class="label label-default">All Nations</span>
                                            @elseif($prod->erp_distributor == 'H')
                                                <span class="label label-default">Hayamax</span>
                                            @elseif($prod->erp_distributor == 'O')
                                                <span class="label label-default">Oderço</span>
                                            @elseif($prod->erp_distributor == 'R')
                                                <span class="label label-default">Rico Peças</span>
                                            @endif
                                        </td>
                                        <td>
                                            @foreach($prod->category as $category)
                                                {{$category->erp_name}}
                                            @endforeach
                                        </td>
                                        <td>
                                            <button href="#" data-toggle="modal" data-target="#view" class="btn btn-default"><i class="glyphicon glyphicon-eye-open"></i></button>
                                            <div class="modal fade" id="view" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                                <div class="modal-dialog" role="document">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                            <h4 class="modal-title" id="myModalLabel">Detalhes</h4>
                                                        </div>
                                                        <div class="modal-body">
                                                            <div class="panel panel-default">
                                                                <div class="panel-heading">
                                                                    <h3 class="panel-title">Informações do produto</h3>
                                                                </div>
                                                                <div class="panel-body">
                                                                    <h5>Nome</h5>
                                                                    <input class="form-control" type="text" placeholder="{{$prod->description->erp_name}}" readonly>
                                                                    <h5>SKU</h5>
                                                                    <input class="form-control" type="text" placeholder="{{$prod->erp_model}}" readonly>
                                                                    <h5>EAN</h5>
                                                                    <input class="form-control" type="text" placeholder="{{$prod->erp_ean}}" readonly>
                                                                    <h5>NCM</h5>
                                                                    <input class="form-control" type="text" placeholder="{{$prod->erp_ncm}}" readonly>
                                                                    <h5>CST</h5>
                                                                    <input class="form-control" type="text" placeholder="{{$prod->erp_cstid}}" readonly>
                                                                    <h5>Marca</h5>
                                                                    <input class="form-control" type="text" placeholder="{{$prod->brand->erp_name}}" readonly>
                                                                    <h5>Categoria</h5>
                                                                    @foreach($prod->category as $category)
                                                                        <input class="form-control" type="text" placeholder="{{$category->erp_name}}" readonly>
                                                                    @endforeach
                                                                    <h5>Distribuidor</h5>
                                                                    <input class="form-control" type="text" placeholder="{{ App\Helpers\ProductDistributorHelper::$distributor[$prod->erp_distributor]}}" readonly>
                                                                </div>
                                                            </div>
                                                            <div class="panel panel-success">
                                                                <div class="panel-heading">
                                                                    <h3 class="panel-title">Informações dos preços</h3>
                                                                </div>
                                                                <div class="panel-body">
                                                                    <h5>Preço custo</h5>
                                                                    <input class="form-control" type="text" placeholder="R$ {{$prod->erp_cost}}" readonly>
                                                                    <h5>Preço venda</h5>
                                                                    <input class="form-control" type="text" placeholder="R$ {{$prod->erp_price}}" readonly>
                                                                </div>
                                                            </div>
                                                            <div class="panel panel-success">
                                                                <div class="panel-heading">
                                                                    <h3 class="panel-title">Informações de peso e medida</h3>
                                                                </div>
                                                                <div class="panel-body">
                                                                    <h5>Peso</h5>
                                                                    <input class="form-control" type="text" placeholder="{{$prod->erp_weight}} kg" readonly>
                                                                    <h5>Comprimento</h5>
                                                                    <input class="form-control" type="text" placeholder="{{$prod->erp_lenght}} cm" readonly>
                                                                    <h5>Largura</h5>
                                                                    <input class="form-control" type="text" placeholder="{{$prod->erp_width}} cm" readonly>
                                                                    <h5>Altura</h5>
                                                                    <input class="form-control" type="text" placeholder="{{$prod->erp_height}} cm" readonly>
                                                                </div>
                                                            </div>
                                                            <div class="panel panel-danger">
                                                                <div class="panel-heading">
                                                                    <h3 class="panel-title">Informações de estoque</h3>
                                                                </div>
                                                                <div class="panel-body">
                                                                    <h5>Quantidade</h5>
                                                                    <input class="form-control" type="text" placeholder="{{$prod->erp_quantity}}" readonly>
                                                                </div>
                                                            </div>
                                                            <div class="panel panel-danger">
                                                                <div class="panel-heading">
                                                                    <h3 class="panel-title">Informações técnicas e descrição</h3>
                                                                </div>
                                                                <div class="panel-body">
                                                                    <h5>Descrição</h5>
                                                                    <p></p>
                                                                </div>
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-default" data-dismiss="modal">OK</button>
                                                            </div>
                                                        </div>

                                                    </div>
                                                </div>
                                            </div>
                                        </td>
                                        <style>
                                            td{
                                                max-width: 100px;
                                                min-width: 80px;
                                            }
                                        </style>
                                        </tbody>

                                    </thread>
                                @endforeach
                            </table>
Run Code Online (Sandbox Code Playgroud)

我的控制器

public function showView($name=null){
    if(View::exists('admin/'.$name))
    {
        $product = Product::paginate(10);
        if(Sentinel::check())
            return view('admin.'.$name)->with('product', $product);
        else
            return redirect('admin/signin')->with('error', 'You must be logged in!');
    }
    else
    {
        return view('admin.404');
    }}
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

Web*_*ion 8

它每次显示你的第一个模态因为每个模态具有相同的id 视图.

所以下面的代码更改,它会工作.

<button href="#" data-toggle="modal" data-target="#view_{{$prod->id}}" class="btn btn-default"><i class="glyphicon glyphicon-eye-open"></i></button>
<div class="modal fade" id="view_{{$prod->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
Run Code Online (Sandbox Code Playgroud)

这将为每个模态创建不同的ID.

这不是让它工作的好方法.

对于每一行,您应该只有一个模态,并在模态显示按钮的单击事件上使用jQuery动态更改数据.

因为这么多记录会使你的HTML文件变大,因此性能会很慢.