text: 
      $.ajaxSetup({
      headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
      }
  });
  
  function select2Static(){
    $(".select-static").select2({
    
        width:'100%',
      theme:'bootstrap',
  });
  
  }
  
  
  $(document).ready(function() {
    
  select2Load();
  });
  
  function select2Load(){
  select2Static();
  // return;
  
  console.log($('.select2').length);
  if ($('.select2').length<1) {
  return; 
  }
  
      $(".select2").select2({
        width:'100%',
      theme:'bootstrap',
      placeholder:'search',
    ajax: {
         dataType: "json",
      url: function () {
  
  
    var url = new URL($(this).attr('data-url'));
    
        var related = $(this).attr('data-related');
        if (related!=null) {
        var split = related.split(',');
        console.log(split);
  
  
        // console.log(related);
  
        if (split.length>0) {
          split.map(function(index, elem) {
          var val = $("select[name="+index+"]").val();
      
      url.searchParams.set(index, val);
  
            // return something;
          })
        }
        }
        console.log(url);
        // console.log(val);
  
        return url;
      },
  
      processResults: function (data) {
      var results = [];
  
      // console.log(data);
      // alert("x");
      // console.log();
      var resultData = JSON.parse(JSON.stringify(data));
      for (var i = 0; i < resultData.length; i++) {
        // Things[i]
        
         results.push({
              id: resultData[i].id,
              text: resultData[i].text
          });
      }
    
      return {
          results: results
      };
  }
    }
  });
  }
  
  
  $(document).on('click','.create-btn',function(){
  
        var src = $(this).attr('data-src');
        var title = $(this).attr('data-title');
        var actionBtn = $(this).attr('data-save');
  
        var large = $(this).attr('data-large');
        var iframe = $(this).attr('data-iframe');
  
    
        if (large!=null) {
          $("#modal .modal-dialog").addClass('modal-lg');
        }
        else{
          $("#modal .modal-dialog").removeClass('modal-lg');
  
        }
  
        $("#modal .modal-body").html('');
         $("#modal .modal-title").text('');
  
        // $("#modal .modal-body").html('');
        $.get(src,function(res){
  
  
          $("#modal .modal-title").text(title);
          $("#modal  .modal-body").html(res);
          if (actionBtn!=null) {
            $(".save-btn").hide();
          }
          else{
            $(".save-btn").show();
  
          }
  
       $("#form").append('<button type="submit" style="display:none" class="submit"></button>');
      // $("#form").submit(function(e) {
      //   /* Act on the event */
      //   alert("x");
      //   $(".save-btn").trigger('click');
      //           e.preventDefault();
  
      // });
  
  // alert("x");
  $("#form").submit(function(event) {
    /* Act on the event */
    event.preventDefault();
    
        $(".save-btn").trigger('click');
  
  
  });
  
  
  
  
       select2Load();
  
  
          // $(".select2").select2();
          var url;
          
  
  
  
  
        });
        var large = $(this).attr('data-large');
        // console.log(large);
        if (large!=null) {
          $("#modal .modal-dialog").addClass('modal-super-lg');
        }
        else{
          var lg =  $(this).attr('data-lg');
          console.log(lg);
          if (lg!=null) {
          $("#modal .modal-dialog").removeClass('modal-super-lg');
  
          $("#modal .modal-dialog").addClass('modal-lg');
  
          }
          else{
          $("#modal .modal-dialog").removeClass('modal-super-lg');
          $("#modal .modal-dialog").removeClass('modal-lg');
  
          }
          
        }
  
      $('#modal').modal({backdrop: 'static', keyboard: false})  
  
        $("#modal").modal("show");
  
      });
  
  
  
      $(document).on('click','.save-btn',function(){
        var entype = ($("#form").attr('enctype') == null ? 0 :1);
        var redirect = ($(this).attr('data-redirect') == null ? 0 :1);
        var path = $(this).attr('data-redirect-to');
  
        // console.log(en);
        // return;
        
  
          $(".loading").show();
          $(this).attr('disabled','disabled');
  
  
  
          // $("#loaderModal").modal("show");
          // return ;
        if (entype==1) {
  // return;
    var formData = new FormData($("#form")[0]);
  
  // console.log(formData);
    $.ajax({
  
              type:'POST',
              url: $("#form").attr('action'),
              data:formData,
              cache:false,
              method: "POST",
              contentType: false,
              processData: false,
              dataType: "JSON",
              success:function(res){
  //              console.log(res);
          $(".save-btn").removeAttr('disabled');
  
              if (res.success) {
  
  
  
             
  $.notify({
    // options
    message: res.msg
  },{
    // settings
    z_index:100000,
    type: 'success'
  });
  
  
  
                $("#modal").modal('hide');
  
                // setTimeout(function(){
                //   location.reload();
                // },1000);
  
   if (redirect==1) {
                location.href = path;
                // alert("XX");
               }
               else{
  
                $("#modal").modal('hide');
                $('#table').DataTable().ajax.reload();
  
               }
  
               
  
               }
  
  
              else{
  
             
  $.notify({
    // options
    message: res.msg
  },{
    // settings
    z_index:100000,
    type: 'danger'
  });
  
  
  
              }
  
          $(".loading").hide();
  
  
  
              }
  
    })
  .fail(function(data, textStatus, xhr) {
    // console.log("erroxr");
  
    // console.log(data);
    if (data.status==422) {
          $(".save-btn").removeAttr('disabled');
  
        $('input').removeClass('is-invalid');
        $('select').removeClass('is-invalid');
        $(".invalid-feedback").remove();
  
      // console.log(data.responseJSON);
      $.each(data.responseJSON.errors, function(index,val) {
        // console.log(index);
        // console.log(val);
        $('[name='+index+']').after("");
  
        $('[name='+index+']').addClass('is-invalid');
        var msg = '<div class="invalid-feedback">'+val+'</div>';
        $('[name='+index+']').after(msg);
         /* iterate through array or object */
      });
    }
  });
  
  
  
  
        }
        else{
          var formData = $("#form").serialize();
            $.ajax({
  
              type:'POST',
              url: $("#form").attr('action'),
              data:formData,
              method: "POST",
              dataType: "JSON",
              success:function(res){
  //              console.log(res);
          $(".save-btn").removeAttr('disabled');
  
              if (res.success) {
  
             
  $.notify({
    // options
    message: res.msg
  },{
    // settings
    z_index:100000,
    type: 'success'
  });
               if (redirect==1) {
                location.href = path;
                // alert("XX");
               }
               else{
  
                $("#modal").modal('hide');
                $('#table').DataTable().ajax.reload();
  
               }
              }
              else{
  
  
             
  $.notify({
    // options
    message: res.msg
  },{
    z_index:100000,
    // settings
    type: 'danger'
  });
  
              }
                      $(".loading").hide();
  
              }
  
    })
  .fail(function(data, textStatus, xhr) {
    // console.log("erroxr");
  
    // console.log(data);
    if (data.status==422) {
          $(".save-btn").removeAttr('disabled');
  
        $('input').removeClass('is-invalid');
        $('select').removeClass('is-invalid');
        $(".invalid-feedback").remove();
  
      // console.log(data.responseJSON);
      $.each(data.responseJSON.errors, function(index,val) {
        // console.log(index);
        // console.log(val);
        $('[name='+index+']').after("");
  
        $('[name='+index+']').addClass('is-invalid');
        var msg = '<div class="invalid-feedback">'+val+'</div>';
        $('[name='+index+']').after(msg);
         /* iterate through array or object */
      });
    }
  });
  
  
        }
        
      });
  
  
  
      $(document).on('click', '.delete-btn', function(event) {
        event.preventDefault();
        var reload = ($(this).attr('data-reload')!=null ? true:false);
        /* Act on the event */
  
        Swal.fire({
    title: 'Are you sure you want to delete?',
    text: "Data will be lost and cannot be recovered",
    type: 'warning',
    showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes',
      cancelButtonText: 'No',
      focusCancel: true,
  
  }).then((result) => {
    if (result.value) {
  
  
        var src = $(this).attr('href');
          var formData = $("#form").serialize();
            $.ajax({
  
              type:'DELETE',
              url: src,
              method: "DELETE",
              data: {
                   _token: $('meta[name="csrf-token"]').attr('content'),
              },
              dataType: "JSON",
              success:function(res){
  //              console.log(res);
              // if (res.status=="1") {
              //   $("#modal").modal('hide');
              if (res.success) {
  
  $.notify({
    // options
    message: res.msg
  },{
    // settings
    z_index:100000,
    type: 'success'
  });
  
                $('#table').DataTable().ajax.reload();
                if(reload){
                  location.reload();
                }
              // }
              }
              else{
                $.notify({
    // options
    message: res.msg
  },{
    // settings
    z_index:100000,
    type: 'danger'
  });
              }
              }
  
    });
  
  
  
    }
  })
  });