can’t get data-source in modal in laravel

  jquery, laravel, php

I am trying to get data-src (youtube link from database) value in my modal, but it’s not fetching . my codes so far :

from controller :

foreach($ondemand_data as $row)
   {
    $ondemand_output .= '

                <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col-xl-4">
                   <div class="aspire-video-content">
                       <div class="aspire-video-thumb">
                           <img src="../storage/webinar/'.$row->image.'" alt="" class="img- 
                     thumbnail">
                           <div class="aspire-video-thumb-content">
                               <button type="button" class="btn video-btn" data-toggle="modal" 
                                 data-src="'.$row->video_link.'" data-target="#myModal">
                                   <img src="../img/video/video-img.png" alt="">
                               </button>
                           </div>
                       </div>
                       <div class="aspire-video-txt-content">
                           <div class="aspire-video-txt" style="height: 160px">
                               '.str_limit($row->description, 180).'
                           </div>
                           <input type="text" value="'.$row->video_link.'" class="" id="get- 
                          video-url">
                           <button type="button" class="btn video-btn aspire-video-btn" data- 
                          toggle="modal" data-src="'.$row->video_link.'" data- 
                    target="#myModal">
                               Watch Now
                           </button>
                       </div>
                   </div>
               </div> 
           ';
   }
  }

and code from my script are (scripts are from the blade page):

    <script>
    $(document).ready(function() {
     
        var $videoSrc;
        $('.video-btn').click(function() {
            $videoSrc = $(this).data("src");
        });
        console.log($videoSrc);
         
        $('#myModal').on('shown.bs.modal', function (e) {
        
            $("#video").attr('src',$videoSrc + "? 
         autoplay=1&amp;modestbranding=1&amp;showinfo=0" );
        })
       
        $('#myModal').on('hide.bs.modal', function (e) {
            
            $("#video").attr('src',$videoSrc);
        })
           
    });
</script>

Please ask me if you need more code for better analysis

Source: Ask PHP

LEAVE A COMMENT