Sunday, July 31, 2022

Ajax load lage with laravel.

 step-1:  HTML

<div class="row">

                    <div class="col-lg-12">  

                        <div class="card mb-0">

                            <div class="tab-content card-body p-0 pt-2">

                                <div class="tab-pane fade active show">

                                    <div class="card-body pt-0">

                                        <div class="card-table table-responsive shadow-0 mb-0 wait">

                                             <div id="load_data"></div> 

                                        </div>

                                    </div>

                                </div>

                            </div>

                        </div> 

                    </div>

                </div>

step-2:  Javascript Link

<script src="{{ asset('/website/assets/wait-me/waitMe.min.js')}}"></script>

step-3: Ajax function

$('.get_data_btn').on('click', function(){ 

            get_data();

        });


        function get_data(){

          var base = '{{url('/')}}';

          var product_life_id =$('.product_id').val();  

          var from_date = $('.from_date').val(); 

          var to_date = $('.to_date').val(); 


          if(product_life_id){

            $('.wait').waitMe({effect : 'facebook', text : 'Please wait...'});

             $.ajax({

                  method: 'GET', 

                  url: base+'/backoffice/report/product-life-cycle/filter', 

                  data: {'from_date' : from_date, 'to_date' : to_date, 'product_life_id' : product_life_id}, 

                  success: function(data){ // What to do if we succeed

                      //console.log(response);  

                      $('#load_data').html(data);

                  },

                  error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail

                      console.log(JSON.stringify(jqXHR));

                      console.log("AJAX error: " + textStatus + ' : ' + errorThrown);

                  }

              }).always(function(){

                    $('.wait').waitMe("hide");

                });


          }else{

            alert('Please first type product name');

          } 

        }



step-4: Create load_data.blade.php

public function product(Request $request){

  return view ('load.load_data');

 }















Thursday, November 26, 2020

Add More Multiple Div and remove div

  <div id="employeement_more">

    <div class="row employeementAppendDiv" style="border-top: 1px dotted #d3d3d3; margin-top: 40px;">

    <input type="hidden" class="index" name="employeement[0][index]" value="0"/>

   <div class="col-md-6">

           <div class="form-group">

                   <label for="designation">Designation</label>

                    <input type="text" name="employeement[0][designation]"  class="form-control designation">

              </div>

            </div>

<div class="col-md-6"> 

        <button type="button" class="btn btn-danger btn-sm remove_from_list_div d-none" style="position: absolute;">

          <i class="fa fa-times"></i>

         </button> 

       </div>

</div>

<div>



<div class="pull-right"

     <button type="button" class="btn btn-success btn-sm pull-right addMoreEmployeement"><span             class="fa fa-plus"></span> Add More</button>  

</div>




$('.addMoreEmployeement').on('click', function(){


            var last_index=$('.employeementAppendDiv').last().index();   


            var cloned=$('.employeementAppendDiv').last().clone(true);


            cloned.find(".remove_from_list_div" ).removeClass('hidden');


            cloned.find(".index" ).attr('name', "employeement["+(last_index+1)+"][index]").val(last_index+1);


            cloned.find(".designation" ).attr('name', "employeement["+(last_index+1)+"][designation]").val('');


            cloned.find(".job_category_department" ).attr('name', "employeement["+(last_index+1)+"][job_category_department]").val('');


            //cloned.find(".duration" ).attr('name', "employeement["+(last_index+1)+"][duration]"); 

            cloned.find(".start_date" ).attr('name', "employeement["+(last_index+1)+"][start_date]").val(''); 

            cloned.find(".end_date" ).attr('name', "employeement["+(last_index+1)+"][end_date]").val(''); 

            cloned.find(".company" ).attr('name', "employeement["+(last_index+1)+"][company]").val('');


            cloned.appendTo( "#employeement_more" );


        });



///////////////////// Remove div ///////////////////////////////


        $('.remove_from_list_div').on('click', function(){


           $(this).closest('.employeementAppendDiv').remove();


        });



////////////////////// Dynamic Datepicker Added /////////////////////////////



  $('body').on('focus',".start_date", function(){  

     $(this).removeClass('hasDatepicker').removeAttr('id').datepicker({

         dateFormat : 'dd/mm/yy',

         changeMonth : true,

         changeYear : true,

         yearRange: '-100y:c+nn',

         maxDate: '-1d'

      });  

   }); 

Sunday, August 30, 2020

Sweet Alert delete using Laravel ?

 Delete btn:

<a href="{!!route('news-letter-delete',$row->id )!!}" class="btn btn-danger deleteBtn pull-right py-0" data-token="{!! csrf_token() !!}" data-id="{!! $row->id !!}"><span class="icofont icofont-trash"> </span></a>


web.php

Route::delete('/news-letter-delete/{id}',

[

'as' => 'news-letter-delete',

'uses' => 'Admin\NletterController@destroy',

'middleware' => ['permission:All|Configuration']

]

)->where('id', '[0-9]+');


Controller:


public function destroy($id)

    {

        $deleteData = Nletter::FindOrFail($id); 


        try{


            $deleteData->delete();


            NletterDetail::where('nletter_id',$id)->delete();


            $bug = 0;

        }

        catch(\Exception $e){

            $bug = $e->errorInfo[1];

        }


        if($bug==0){

            echo "success";

              

        }else{

            echo 'error';

        } 

         

    }


CSS :

      <!-- sweetalert css -->

   <link rel="stylesheet" href="{!! asset('js/sweetalert/sweetalert.css') !!}">


JS: include  master.blade.php 


<script src="{!! asset('js/sweetalert/sweetalert-dev.js') !!}"></script>

   <script type="text/javascript">

     $(document).on('click', '.deleteBtn', function () {

                var actionTo=$(this).attr('href');

                var token=$(this).attr('data-token');

                var id=$(this).attr('data-id');


                swal({

                        title: "Are you sure?",

                        text: "You will not be able to recover this imaginary file!",

                        type: "success",

                        showCancelButton: true,

                        confirmButtonClass: 'btn-danger',

                        confirmButtonColor: "#DD6B55",

                        confirmButtonText: 'Yes, delete it!',

                        cancelButtonText: "Cancel",

                        closeOnConfirm: false,

                        closeOnCancel: false

                    },

                    function (isConfirm) {

                        if (isConfirm) {

                            $.ajax({

                                url:actionTo,

                                type: 'post',

                                data: {_method: 'delete',_token:token},

                                success: function (data) {


                                    if (data == 'hasForeignKey') {

                                        swal({

                                            title: "Oops!",

                                            text: "This data is used anywhere",

                                            type: "error"

                                        });

                                    } else if(data == 'success'){

                                        swal({

                                                title: "Deleted!",

                                                text: "Your information delete successfully.",

                                                type: "success"

                                            },

                                            function (isConfirm) {

                                                if (isConfirm) {

                                                    $('.' + id).fadeOut();

                                                }

                                            });

                                    }else{

                                        swal({

                                            title: "Fail to Delete!",

                                            text: "Something Error Found !, Please try again.",

                                            type: "error"

                                        });

                                    }

                                }


                            });

                        } else {

                            swal("Cancelled", "Your data is safe .", "error");

                        }

                    });

                return false;

            });

  </script>

Thursday, August 20, 2020

Vue js delete ?

 HTML:

<button type="button" @click="deleteComment(row.id,index)" ><i class="fa fa-trash-o text-danger hand"></i></button>

Web.php:

 Route::delete('/delete-ticket-comment/{id}', 'Admin\TaskController@deleteTicketComment')->name('backoffice.delete-ticket-comment');

Controller:

public function deleteTicketComment($id){ 

        $taskComment =TaskRemark::findOrFail($id)->delete(); 

    }

Vue Js 

deleteComment:function(id,index) {

                  var ref = this;

                     swal({

                        title: "Are you sure?",

                        text: "You will not be able to recover this data!",

                        type: "warning",

                        showCancelButton: true,

                        buttonsStyling: false,

                        confirmButtonClass: 'btn btn-primary',

                        cancelButtonClass: 'btn btn-light',

                        confirmButtonText: "Yes, delete!",

                        cancelButtonText: "No, cancel!"

                         

                    }).then((willDelete) => {

                           if (willDelete) {

                                axios({

                                  method:'delete',

                                  url:"{{ url('backoffice/delete-task-comment') }}/"+id, 

                                  

                                }).then(function (response) {

                                     ref.alert('Delete Successful','success');

                                     ref.task_remarks.splice(index, 1);

                             });

                           } else {

                                 return true;

                        }

                    }); 

                

                }

            },


Others :

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>


deleteComment:function(id,index) {

                  var ref = this;

                     swal({ 

                        title: "Are you sure?",

                        text: "You will not be able to recover this data!",

                        icon: "warning",

                        buttons: true,

                        dangerMode: true,

                         

                    }).then((willDelete) => {

                           if (willDelete) {

                                axios({

                                  method:'delete',

                                  url:"{{ url('backoffice/delete-task-comment') }}/"+id, 

                                  

                                }).then(function (response) {

                                     //ref.alert('Delete Successful','success');

                                     swal("Delete Successful!");

                                     ref.task_remarks.splice(index, 1);

                             });

                           } else {

                                 swal("Your imaginary file is safe!");

                        }

                    });  

                }

Saturday, July 25, 2020

Ajax delete with sweetalert & toastr message using laravel ??


HTML:

@foreach($user-> as $key => $row)
                        <tr class="{{$row->id}}">
                            <td>
                                 <a class="deleteAddress" data-id="{{ $row->id }}" title="Delete Shipping Address"><i class="fa fa-trash" aria-hidden="true"></i></a>
                            </td>    
                        </tr>

@endforeach

web.php:

Route::get('/delete-shipping-address/{id}', 'Website\AccountController@delete_shipping_address')->name('delete-shipping-address');

Controller:

 public function delete_shipping_address($id){
      $shipping_address = Address::findOrFail($id);
      $shipping_address->delete();
      return response()->json(['status' => 'success', 'message' => 'Delete Address successfully!']);


  }



css :

<link rel="stylesheet" href="{{ asset('backoffice/global_assets/bootstrap-sweetalert/dist/sweetalert.css') }}">

 <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.css">

JS:

<script src="{{ asset('backoffice/global_assets/bootstrap-sweetalert/dist/sweetalert.min.js') }}"></script>

<script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>


<script type="text/javascript">
    $(function(){
       $('.deleteAddress').click(function() {

            var id=$(this).data('id'); 
            var url = "{{URL('delete-shipping-address')}}";
            var dltUrl = url+"/"+id;

            swal({
              title: "Are you sure?",
              text: "Press Yes to confirm or press No to cancel.",
              type: "warning",
              showCancelButton: true,
              confirmButtonClass: "btn-danger",
              confirmButtonText: "Yes",
              cancelButtonText: "No",
              closeOnConfirm: true,
              closeOnCancel: true
            },
            function(isConfirm){
              if(isConfirm){

                $.ajax({
                    url: dltUrl,
                    type: 'GET',
                    data: { 
                        id:id,
                        _token: "{{ csrf_token() }}"
                    },
                    success: function(data){ 
                        if (data.status == 'success') {
                            toastr.success(data.message); 
                        }  

                        location.reload(); 
                    },
                   
                });
             
              }
            });

       }); 
       
    });

    $(function(){
        toastr.options = {
        "closeButton": true,
        "debug": false,
        "positionClass": "toast-top-right",
        "onclick": null,
        "showDuration": "1000",
        "hideDuration": "1000",
        "timeOut": "5000",
        "extendedTimeOut": "1000",
        "showEasing": "swing",
        "hideEasing": "linear",
        "showMethod": "fadeIn",
        "hideMethod": "fadeOut"
    }

    @if(Session::has('message'))
        var type = "{{ Session::get('alert-type', 'info') }}";
        switch(type){
            case 'info':
                toastr.info("{{ Session::get('message') }}");
                break;

            case 'warning':
                toastr.warning("{{ Session::get('message') }}");
                break;
            case 'success':
                toastr.success("{{ Session::get('message') }}");
                break;
            case 'error':
                toastr.error("{{ Session::get('message') }}");
                break;
        }
    @endif  
    });

</script>

Thursday, July 23, 2020

Ajax Insert Crude with toaster message .???

HTML:

<form action="{{ url('email-registration') }}" method="POST" id="user_register_bng">
                  {{ csrf_field() }}
                    <div class="form-group required-field">
                      <label for="email">Email Address</label>
                      <input type="email" name="email" id="email" class="form-control {{ $errors->has('email') ? 'border-danger' : '' }}" value="{{ old('email') }}" data-validation="email">
                        @if ($errors->has('email'))
                          <span class="text-danger">{{ $errors->first('email') }}</span><br/>
                        @endif
                    </div>
                    <div class="form-group required-field">
                      <label for="password">Password</label>             
                      <input type="password" name="password" id="password" class="form-control {{ $errors->has('password') ? 'border-danger' : '' }}" data-validation="required">
                        @if ($errors->has('password'))
                          <span class="text-danger">{{ $errors->first('password') }}</span><br/>
                        @endif
                    </div>

                    <div class="form-group required-field">
                      <label for="password_confirmation">Retype Password</label>             
                      <input type="password" name="password_confirmation" id="password_confirmation" class="form-control {{ $errors->has('password_confirmation') ? 'border-danger' : '' }}" data-validation="required">
                        @if ($errors->has('password_confirmation'))
                          <span class="text-danger">{{ $errors->first('password_confirmation') }}</span><br/>
                        @endif
                    </div>


                    <button type="submit" id="btnSubmitBng" class="btn btn-block btn-primary mt-2">SIGN UP</button>
                 
                </form>


JS:

<script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>

<script type="text/javascript">
    $.ajaxSetup({

        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
           }
       });

       $("#btnSubmitBng").click(function(e){ 

        e.preventDefault();
        var email = $("#email").val(); 
        var password = $("#password").val(); 
        var password_confirmation = $("#password_confirmation").val();


        $.ajax({

           type:'POST',
           url:'email-registration',
           data:{ password:password, email:email,password_confirmation:password_confirmation},
           success:function(data){

               if (data.status == 'success') {
                    toastr.success(data.message);
                } else if (data.status == 'error') {
                    toastr.error(data.message);
                } else {
                    toastr.error(data.message);
                }
             
           }

        });

       });
 
  </script>

web.php:

Route::post('/email-registration', 'Auth\RegisterController@emailRegistration')->name('email-registration');


Controller:

public function emailRegistration(Request $request){

        $this->validate($request, [
            'email' => 'email',
            'password' => 'min:6|required_with:password_confirmation|same:password_confirmation',
            'password_confirmation' => 'min:6'
        ]);

        $existingUser = User::where('email', $request->email)->first();

        if($existingUser){
             return response()->json(['status' => 'erroe', 'message' => 'Your email already exist !']);
        }
       
        $input = $request->all(); 
   
        $input['password'] = Hash::make($request->password);
     
       
        $usertData = User::create($input);
       
         return response()->json(['status' => 'success', 'message' => 'User Registration successfully!']);

    }

Sunday, July 19, 2020

Current position using geolocation in Laravel ?

HTML:

<div id="vip_privilege_div"></div>



JS:

<script src="{{ asset('website/assets/js/geolocation/codegrid.js') }}"></script>

<script type="text/javascript">

  $(function(){

    $("#vip_privilege_div").html('<a href="{{ url("/privilege" ) }}" title="Become a VIP">VIP Privileges</a>');

    var grid = codegrid.CodeGrid();

    navigator.geolocation.getCurrentPosition(function(pos){

        var lat=pos.coords.latitude;
        var lng=pos.coords.longitude;

        grid.getCode (lat, lng, function (err, code) {
            
          if(code=="bd"){

             var url ='{{ url("/privilege" ) }}';
             $("#vip_privilege_div").html('<a href="'+url+'" title="Become a VIP">VIP Privileges</a>');

          }else{

            var url_global ='{{ url("/global") }}';
            $("#vip_privilege_div").html('<a href="'+url_global+'" title="Become a VIP">The Mall Global</a>'); 

          }

        });


    });
</script>

Ajax load lage with laravel.

 step-1:  HTML <div class="row">                     <div class="col-lg-12">                           <d...