Current File : //home/tradevaly/text.tradevaly.com.bd/resources/views/user/pages/editproduct.blade.php
@extends('user.ayaan.master')

@push('style')
 <link href="{{ asset('/assets/libs/select2/select2.min.css') }}" rel="stylesheet" type="text/css" />
@endpush

@section('content')
<div class="container-fluid">
  <div class="row">
    <div class="col-md-12">
      <div class="card">
        <div class="card-header card-header-icon card-header-info">
          <h4 class="card-title">EDIT PRODUCT
          </h4>
        </div>
        <div class="card-body">
          <form action="{{route('user.editproducts', $product->id)}}" method="POST" enctype="multipart/form-data">@csrf
            <div class="row">
             <div class="col-md-8 mb-4 mb-3 col-sm-6">
                  <img style="width:100px; margin-bottom:20px;" src="{{asset('storage/images/admin/product/'.$product->image.'')}}" alt="NO image avialable"> <br/>
                  <label class="bmd-label-floating">Product Image</label>
                  <input type="file" id="files1" name="image" class="form-control" >
              </div>
            </div>
            <div class="row">
              <div class="col-md-8 mb-4">
                <div class="form-group">
                  <label class="bmd-label-floating">Product Name</label>
                  <input type="text" name="title" value="{{$product->title}}" class="form-control" >
                </div>
              </div>
              <div class="col-md-8 mb-4">
                <div class="form-group">
                <label class="bmd-label-floating">Category Name</label>
                <select class="form-control" name="category_id">
                    <option disabled selected>Select Category</option>
                    @foreach ($caegories as $category)
                    <option value="{{$category->id}}" @if($product->child_id != 0) 
                    @if($product->child_id == $category->id) selected 
                    @endif 
                    @else 
                    @if($product->sub_id == $category->id) selected @endif @endif>{{$category->name}}</option>
                    @endforeach
                  </select>
                  </div>
            </div>
            @php
            $subcat = \App\Models\Category::where('id', $product->sub_id)->first();
            $childcat = \App\Models\Category::where('id', $product->sub_id)->first();
            @endphp
            
             <div class="col-md-8 mb-4">
                <div class="form-group">
                    <label class="bmd-label-floating">Sub Category</label>
                    <select class="form-control" name="sub_id" >
                        @if($product->child_id == 0) <option value="{{$product->category_id}}" selected>{{$product->category->name}}</option> @else <option value="{{$product->sub_id}}" selected>{{$subcat->name}}</option> @endif
                     </select>
                  </div>
            </div>
            
             <div class="col-md-8 mb-4">
                <div class="form-group">
                    <label class="bmd-label-floating">Child Category</label>
              <select class="form-control" name="child_id">
                   @if($product->child_id == 0) <option value="">Select Child Category</option> @else <option value="{{$product->category_id}}">{{$product->category->name}}</option> @endif
                  </select>
                  </div>
            </div>
         
                <div class="col-md-6 mb-3">
                    <div class="form-group">
                        <label class="bmd-label-floating">Select Tags</label>
                        <select class="form-control"  name="tags[]" id="example" multiple>
                        <option selected>Select Tags</option>
                            @foreach ($tags as $category)
                            <option value="{{$category->name}}">{{$category->name}}</option>
                            @endforeach
                         </select>
                    </div>
                </div>
                
                
                <div class="col-md-8 mb-4">
                <div class="form-group">
                  <label class="bmd-label-floating">Youtube Video Url</label>
                  <input type="text" name="video" value="{{$product->video}}" class="form-control" >
                </div>
              </div>
            
             <div class="col-md-8 mb-4">
                <div class="form-group">
                  <label class="bmd-label-floating">Process Time</label>
                  <input type="text" name="processing_time"  value="{{$product->processing_time}}" class="form-control" >
                </div>
              </div>
            
            
            <div class="col-md-8 mb-4">
                <div class="form-group">
                  <label class="bmd-label-floating">Port</label>
                  <input type="text" name="port" value="{{$product->port}}" class="form-control" >
                </div>
              </div>
              
                <div class="col-md-8 mb-4">
                <div class="form-group">
                  <label class="bmd-label-floating">Unit</label>
                  <input type="text" name="unit" value="{{$product->unit}}" class="form-control" >
                </div>
              </div>
              
              
              <div class="col-md-8 mb-4">
                <div class="form-group">
                  <label class="bmd-label-floating">Supply Ability</label>
                  <input type="text" name="supply_ability"  value="{{$product->supply_ability}}" class="form-control" >
                </div>
              </div>
              
        
            
            <div class="col-md-8 mb-4">
                    <div class="form-group">
                  <select class="form-control" name="payment_method">
                        <option disabled selected>Payment Method</option>
                        @foreach ($method as $category)
                        <option value="{{$category->name}}" @if($product->payment_method == $category->name) selected @endif>{{$category->name}}</option>
                        @endforeach
                      </select>
                </div>
                </div>
            
            
             <div class="col-md-8 mb-4">
                <div class="form-group">
                  <label class="bmd-label-floating">Origin</label>
                  <input type="text" name="origin" value="{{$product->origin}}" class="form-control" >
                </div>
              </div>
            
             <div class="col-md-8 mb-4">
                <div class="form-group">
                  <label class="bmd-label-floating">Location</label>
                  <input type="text" name="location"  value="{{$product->location}}"  class="form-control" >
                </div>
              </div>
              
              
               <div class="col-md-8 mb-4">
                <div class="form-group">
                   <label class="bmd-label-floating"></label>
                  <select class="form-control" name="currency" >
                      <option value="">Select Currency</option>
                      @foreach(\App\Models\Country::whereNotNull('currency')->orderBy('currency', 'asc')->get() as $currency)
                      <option value="{{$currency->currency}}" @if($currency->currency == $product->currency) selected @endif>{{$currency->currency}}</option>
                      @endforeach
                  </select>
                </div>
              </div>
              
              
               <div class="col-md-8 mb-4">
                <div class="form-group">
                  <label class="bmd-label-floating">Stock</label>
                  <input type="text" name="stock"  value="{{$product->stock}}" class="form-control" >
                </div>
              </div>
              
              
               <div class="col-md-8 mb-4 mb-5">
                <div class="form-group">
                  <h3 class="mb-3">Enter Description</h3>
                  <textarea  id="editor" name="des" class="form-control mb-5" placeholder="Enter Details">{!! $product->details !!}</textarea>
                </div>
              </div>
              
          
            </div>
            <div class="row">
              <div class="col-md-3 col-sm-6">
                  <img style="width:50px;" src="{{asset('storage/images/admin/product/'.$product->gallary1.'')}}" alt="NO image avialable"> <br/>
                  <label class="bmd-label-floating field">Product Image 1</label>
                  <input type="file" id="files2" name="gallary1" class="form-control">
                  
              </div>
              <div class="col-md-3 col-sm-6">
              <img style="width:50px;" src="{{asset('storage/images/admin/product/'.$product->gallary2.'')}}" alt="NO image avialable"> <br/>
                  <label class="bmd-label-floating">Product Image 2</label>
                  <input type="file" id="files3" name="gallary2" class="form-control">
                  
              </div>
              <div class="col-md-3 col-sm-6">
                  <img style="width:50px;" src="{{asset('storage/images/admin/product/'.$product->gallary3.'')}}" alt="NO image avialable"> <br/>
                  <label class="bmd-label-floating">Product Image 3</label>
                  <input type="file" id="files4" name="gallary3" class="form-control">
                  
              </div>
              <div class="col-md-3 col-sm-6">
                  <img style="width:50px;" src="{{asset('storage/images/admin/product/'.$product->gallary4.'')}}" alt="No image avialable"><br/>
                  <label class="bmd-label-floating">Product Image 4</label>
                  <input type="file" id="files5" name="gallary4" class="form-control">
              </div>
            </div>
            <button type="submit" class="btn btn-info pull-right mt-4">Upload</button>
            <div class="clearfix"></div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
@stop

@section('script')
<script src="{{ asset('/assets/libs/select2/select2.min.js') }}"></script>

    <!-- dropzone plugin -->
    <script src="{{ asset('/assets/libs/dropzone/dropzone.min.js') }}"></script>
    <script src="{{ asset('assets/libs/tinymce/tinymce.min.js') }}"></script>
    <!-- init js -->
    <script src="{{ asset('/assets/js/pages/ecommerce-select2.init.js') }}"></script>
    <script src="{{ asset('assets/js/pages/form-editor.init.js') }}"></script>
<script>
$(function() {
$('#example').select2({
         multiple: true,
         maximumSelectionSize: 1
    });
});
</script>
<script>
       $(document).ready(function() {
  if (window.File && window.FileList && window.FileReader) {
    $("#files5").on("change", function(e) {
      var files = e.target.files,
        filesLength = files.length;
      
        var f = files[0]
        var fileReader = new FileReader();
        fileReader.onload = (function(e) {
          var file = e.target;
          $("<span class=\"pip\">" +
            "<img class=\"imageThumb\" src=\"" + e.target.result + "\" title=\"" + file.name + "\"/>" +
            "<br/><span class=\"remove\">Remove image</span>" +
            "</span>").insertAfter("#files5");
          $(".remove").click(function(){
            $(this).parent(".pip").remove();
          });
          
          // Old code here
          /*$("<img></img>", {
            class: "imageThumb",
            src: e.target.result,
            title: file.name + " | Click to remove"
          }).insertAfter("#files").click(function(){$(this).remove();});*/
          
        });
        fileReader.readAsDataURL(f);
      
      console.log(files);
    });
  } else {
    alert("Your browser doesn't support to File API")
  }
});
    </script>



<script>
       $(document).ready(function() {
  if (window.File && window.FileList && window.FileReader) {
    $("#files2").on("change", function(e) {
      var files = e.target.files,
        filesLength = files.length;
      
        var f = files[0]
        var fileReader = new FileReader();
        fileReader.onload = (function(e) {
          var file = e.target;
          $("<span class=\"pip\">" +
            "<img class=\"imageThumb\" src=\"" + e.target.result + "\" title=\"" + file.name + "\"/>" +
            "<br/><span class=\"remove\">Remove image</span>" +
            "</span>").insertAfter("#files2");
          $(".remove").click(function(){
            $(this).parent(".pip").remove();
          });
          
          // Old code here
          /*$("<img></img>", {
            class: "imageThumb",
            src: e.target.result,
            title: file.name + " | Click to remove"
          }).insertAfter("#files").click(function(){$(this).remove();});*/
          
        });
        fileReader.readAsDataURL(f);
      
      console.log(files);
    });
  } else {
    alert("Your browser doesn't support to File API")
  }
});
    </script>

<script>
       $(document).ready(function() {
  if (window.File && window.FileList && window.FileReader) {
    $("#files3").on("change", function(e) {
      var files = e.target.files,
        filesLength = files.length;
      
        var f = files[0]
        var fileReader = new FileReader();
        fileReader.onload = (function(e) {
          var file = e.target;
          $("<span class=\"pip\">" +
            "<img class=\"imageThumb\" src=\"" + e.target.result + "\" title=\"" + file.name + "\"/>" +
            "<br/><span class=\"remove\">Remove image</span>" +
            "</span>").insertAfter("#files3");
          $(".remove").click(function(){
            $(this).parent(".pip").remove();
          });
          
          // Old code here
          /*$("<img></img>", {
            class: "imageThumb",
            src: e.target.result,
            title: file.name + " | Click to remove"
          }).insertAfter("#files").click(function(){$(this).remove();});*/
          
        });
        fileReader.readAsDataURL(f);
      
      console.log(files);
    });
  } else {
    alert("Your browser doesn't support to File API")
  }
});
    </script>
    
    
    
    <script>
       $(document).ready(function() {
  if (window.File && window.FileList && window.FileReader) {
    $("#files4").on("change", function(e) {
      var files = e.target.files,
        filesLength = files.length;
      
        var f = files[0]
        var fileReader = new FileReader();
        fileReader.onload = (function(e) {
          var file = e.target;
          $("<span class=\"pip\">" +
            "<img class=\"imageThumb\" src=\"" + e.target.result + "\" title=\"" + file.name + "\"/>" +
            "<br/><span class=\"remove\">Remove image</span>" +
            "</span>").insertAfter("#files4");
          $(".remove").click(function(){
            $(this).parent(".pip").remove();
          });
          
          // Old code here
          /*$("<img></img>", {
            class: "imageThumb",
            src: e.target.result,
            title: file.name + " | Click to remove"
          }).insertAfter("#files").click(function(){$(this).remove();});*/
          
        });
        fileReader.readAsDataURL(f);
      
      console.log(files);
    });
  } else {
    alert("Your browser doesn't support to File API")
  }
});
    </script>
<script>
$(document).ready(function() {
      $(".btn-success").click(function(){ 
          var lsthmtl = $(".clone").html();
          $(".increment").after(lsthmtl);
      });
       $("body").on("click",".btn-danger",function(){ 
          $(this).parents("#cloning").remove();
      });
    });
    
    
    
    
    
    
    $(document).on('change', '[name=category_id]', function() {
            var child_id = $(this).val();
            get_cat(child_id);
        });
        
        
        function get_cat(child_id) {
            $('[name="sub_id"]').html("");
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: "{{ route('ajax.cat')}}",
                type: 'POST',
                data: {
                    sub_id  : child_id
                },
                success: function (response) {
                    $(".select2").select2();
                    var obj = JSON.parse(response);
                    if(obj != '') {
                        $('[name="sub_id"]').html(obj);
                    }
                }
            });
        }
        
        
        
        
        
        
        
        $(document).on('change', '[name=sub_id]', function() {
            var child_id = $(this).val();
            get_child(child_id);
        });
        
        
        function get_child(child_id) {
            $('[name="child_id"]').html("");
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: "{{ route('ajax.subcat')}}",
                type: 'POST',
                data: {
                    sub_id  : child_id
                },
                success: function (response) {
                    $(".select2").select2();
                    var obj = JSON.parse(response);
                    if(obj != '') {
                        $('[name="child_id"]').html(obj);
                    }
                }
            });
        }
        
        
        
        
</script>
@endsection