mateog98's avatar

Why my modal shows every image and not only the selected one?

Hi im having and issue with a modal in my view, it seems that it is not identifying the id im selecting and it is showing every uploaded photo but i only want to show the selected one.

So this is my modal:

      <div class="modal fade" id="DetalleTicketView" tabindex="-1" role="dialog" style="z-index: 1050; display:none; width:100%" aria-hidden="true">
        <div class="modal-dialog" role="document" style="max-width:75%;">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Remito</h5>
                    <button type="button" class="close btn btn-danger" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true"><i class="fas fa-times-circle"></i></span>
                    </button>
                </div>
                <div class="modal-body">
                    <table id="example1" class="table table-striped table-responsive" width="100%">
                        
                        <tbody>
                           
                            @foreach($file as $key => $detalleTicket)
                            <tr>                                   
                                
                                
                                
                                <img src="{{asset('storage/' . $detalleTicket->remitoCliente)}}" alt="">
                            
                            </tr>
                            @endforeach
                        </tbody>
                    
                    </table>
                </div>
            </div>
        </div>
    
    </div>

</section>

And this is the button i press so that the modal appears:

          <a title="Info" id="info" class="btn btn-sm btn-info" data-toggle="modal" data-idUpdate="'.$detalleTicket->id.'" data-target="#DetalleTicketView"><i class="fa fa-eye"></i></a>

So now if i upload to different pictures and visualize one it shows me both of them one above the other one.

DetalleTicketController:

                          class DetalleTicketController extends Controller
              {
                         public function view(){ 
                                $file = DetalleTicket::all();
                               return view('backend.detalle_ticket.view-detalle-ticket', compact('file'));
                        }

                       public function add(){
                           $detalleTicket['tickets'] = Ticket::all();        
                           $detalleTicket['products'] = Product::all();

                            return view('backend.detalle_ticket.add-detalle-ticket', $detalleTicket);
                          }

                         public function store(Request $request){
                        /*dd($request->all());*/
                        $detalleTicket = new DetalleTicket();

                         $detalleTicket->ticket_id = $request->ticket_id;
                         $detalleTicket->product_id = $request->product_id;
                         $detalleTicket->serial_number = $request->serial_number;
                         $detalleTicket->quantity = $request->quantity;
                         $detalleTicket->commentary = $request->commentary;
                         $path = request()->file('remitoCliente')->store('archivos'); 
                         $detalleTicket->remitoCliente = $path;

                        $detalleTicket->save();
                         Session::flash('success');
                          return redirect()->route('detalles-tickets.view', $path);
         }

              public function edit($id){
                   $data['editData'] = DetalleTicket::find($id);
                    $data['tickets'] = Ticket::all();
                    $data['products'] = Product::all();


                       return view('backend.detalle_ticket.edit-detalle-ticket', $data);
                }

                public function update(Request $request, $id){
                      $detalleTicket = DetalleTicket::find($id);

       
                     $detalleTicket->ticket_id = $request->ticket_id;
                     $detalleTicket->product_id = $request->product_id;
                    $detalleTicket->serial_number = $request->serial_number;
                     $detalleTicket->quantity = $request->quantity;
                    $detalleTicket->commentary = $request->commentary;
                      $path = request()->file('remitoCliente')->store('archivos'); 
                     $detalleTicket->remitoCliente = $path;

                      $detalleTicket->save();

                       Session::flash('success');
                       return redirect()->route('detalles-tickets.view');
             }

                public function delete($id){
                     $detalleTicket = DetalleTicket::find($id);
                     $detalleTicket->delete();
                     return redirect()->route('detalles-tickets.view');
             }

           }
0 likes
2 replies
jlrdw's avatar

Looks like your foreach is looping all.

mateog98's avatar

I took out the foreach and i still have the same issue

Please or to participate in this conversation.