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>

Wednesday, July 15, 2020

Show More/Vew More Button in Laravel & Ajax in single Page ?

blade.php

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

<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 my-4">
                    <center>
                        <button id="loadMoreData" data-pos="{{ $take }}" class="btn btn-primary view_btn_second">Show More</button>
                    </center>
                </div>


Js:

script type="text/javascript">

     $('#loadMoreData').on('click', function(){

        var pos=$(this).data('pos');
        var offer_id="{{ $offer->id }}";

        //$("#loadMoreData").html("Loading....");

        $.ajax({

            url:'{{ route("loadmore.load_data") }}',
            method : "GET",
            data : {pos: pos, offer_id: offer_id},

             success:function(res){

                //console.log(res);

                res.products.forEach(function(row){

                    var html='';
                    html+="<div class='col-6 col-md-4 col-lg-3 col-xl-3 col'>";
                    html+="<div class='product fixed_hight'>";

                    html+="<figure class='product-image-container image-frame'>";
                    html+="<a class='product-image' href='"+row.product_url+"'>";
                    html+="<img class='product_img_tag' src='"+row.product_image_url+"' alt='"+row.name+"'/>";
                    html+="</a>";
                    html+="<a href='"+row.quick_view_url+"' class='btn-quickview'>Quick View</a>";
                    html+="</figure>";

                    html+="<div class='product-details'>";

                    html+="<h1 class='text-left product-category'><a href='"+row.brand_url+"'>"+row.brand_name+"</a></h1>";


                    html+="<h1 class='product-title text-left'><a href='"+row.product_url+"'>"+row.brand_product_title+"</a></h1>";

                    html+="<span><div class='price-box float-left'>";

                    if(row.old_price_status){
                      html+="<span class='old-price'>৳ "+row.price_tax_inc+"</span>";
                    }

                    html+="<span class='product-price'>৳ "+row.price+"</span>";

                    html+="</div></span>";

                    html+="</div><br>";
                    //End of product detail

                    if(row.product_in){

                      html+="<span style='position: absolute;bottom: 0px;right: 28%;' class='paction add-cart cursor_pointer addToCart' data-link='"+row.add_to_cart_url+"' data-product_id='"+row.id+"'  data-product_name='"+row.name+"' data-old_price='"+row.price_tax_inc+"' data-product_price='"+row.price+"' data-product_slug='"+row.slug+"' data-product_image='"+row.thumbnail_image+"' title='Add to Cart'><span>Add to Cart</span></span>";

                    }else{

                      html+="<span style='position: absolute;bottom: 0px;right: 28%;color: #c1b6b6' class='paction add-cart cursor_pointer' title='Out of stock'><span>Out of Stock</span></span>";

                    }

                    html+="</div>";
                    html+="</div>";

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

                });

                if(res.next_pos) $('#loadMoreData').data('pos', res.next_pos);
                else $('#loadMoreData').hide();

                $('.product_img_tag').on('error', function(){
                  //$(this).src=res.default_img;
                  $(this).attr("src", res.default_img);
                });

</script>

web.php
Route::get('/loadmore/load_data', 'Website\HomeController@load_data')->name('loadmore.load_data');

Controller:

public function load_data(Request $request){

    $pos=$request->pos;
    $offer_id=$request->offer_id;

    $offer_image = Offer::where('id', $offer_id)->first();
    $offer =$offer_image;
    $offer_cat_ids = OfferCategory::where('offer_id', $offer_id)->pluck('category_id')->toArray();

    $offer_cats =Category::whereIn('id',$offer_cat_ids)->get();

    $offer_children = Offer::where('parent_id',$offer_id)->get();

    $cat_product_ids =ProductCategory::where('category_id',$offer_cat_ids)->pluck('product_id')->toArray();

    $offer_product_ids=[];

    if($offer->offerDetails){
       $offer_product_ids = $offer->offerDetails->whereIn('product_id',$cat_product_ids)->pluck('product_id')->toArray();
    }
   
    $take = 4;

    $products = Product::with([
      'category','thumbnail'
    ])->whereIn(
      'id', $offer_product_ids
    )->where([
      'status'=>1,
      'available'=>1,
      'product_type'=>'step_one'
    ])->orderBy('id','DESC')->skip($pos)->take($take)->get();

    $produsts_data=[];
    $carbon = new \Carbon\Carbon;

    foreach($products as $product){

      $price = 0;
      $old_price_status = 0;
   
      if($product->offer()->exists() && $product->offer->status==1 && $product->offer->end_date !=null) {
          if ($carbon->now()->diffInSeconds($carbon->parse($product->offer->end_date), false) >= 0) {
              $price = $product->price_tax_inc - $product->discount_amount;
              if ($product->discount_amount >0 ) {
              $old_price_status =1;                         
              }                     
          }else{
              $price = $product->price_tax_inc;
          }                     
      }else{
          $price = $product->price_tax_inc;
      }

      array_push($produsts_data, [
        'id'=>$product->id,
        'name'=>$product->name,
        'price'=>$price,
        'slug'=>$product->slug,
        'product_url'=>url('product', $product->slug),
        'product_image_url'=>asset("backoffice/images/products/regular/".cn($product, 'thumbnail.image', '#')),
        'quick_view_url'=>url('product/quick_view', $product->slug),
        'brand_url'=>route('home.brand.products', ['brand'=>cn($product, 'brand.slug', '#')]),
        'brand_name'=>cn($product, 'brand.name', NULL),
        'brand_product_title'=>str_limit($product->name, 50),
        'old_price_status'=>$old_price_status,
        'price_tax_inc'=>$product->price_tax_inc,
        'product_in'=>$product->product_in,
        'add_to_cart_url'=>url('add-to-cart', $product->id),
        'thumbnail_image'=>cn($product, 'thumbnail.image', '#')
      ]);

    }

    if($take > $products->count()){
      $next_pos=NULL;
    }else{
      $next_pos=$pos+$take;
    }

    return [
      'next_pos'=>$next_pos,
      'products'=>$produsts_data,
      'default_img'=>asset('website/assets/images/default.jpg'),
    ];

  }

Tuesday, July 14, 2020

Count Foreach loop with beak in Laravel ?

                           <?php $count = 0; ?>
                                  @foreach($row->children as $column) 
                                       <?php if($count ==4) break; ?>
                                    <div class="col-md-3" style="float: left;">
                                        <a href="{{ route('home.offer.products.cat', ['offer'=>@$offer_id, 'category'=>@$column->id]) }}" class="product-image">
                                            @if(file_exists( public_path().'/backoffice/images/categories/thumbnail/'.@$column->thumbnail->image ) && @$column->thumbnail->image != null)
                                            <img src="{{ asset('/backoffice/images/categories/thumbnail').'/'.@$column->thumbnail->image }}" alt="{{ @$column->name }}" style="border-radius: 50%">
                                            @else                                             
                                                <img src="{{ asset('/website/assets/images/default.jpg')}}" alt="{{ @$column->name }}" style="width: 360px; height: 250px;">
                                            @endif
                                        </a>
                                       
                                         <div class="product-details">
                                            <h1 class="text-center product-category mt-3" style=""><a href="{{ route('home.offer.products.cat', ['offer'=>@$offer_id, 'category'=>@$column->id]) }}">{{ $column->name }}</a></h1>
                                         </div>
                                   </div>
                                   <?php $count++; ?>
                     
                                  @endforeach

Monday, July 13, 2020

Previous URL in Laravel ?

Previous URL
 // mostafij/product/8
 $previous_url    = str_replace(url('/'), '', url()->previous());
 $previous_url_id =  substr($previous_url, 32);

Ans : 8


Ajax load lage with laravel.

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