I got the string from the ajax and passed the string in url as 1,2,3,4,5,6
After using explode function,
i.e. $explode_id = explode(',', $request->data);
I got the output as
["1","2","3","4","5","6"]
But I want the data as: [1,2,3,4,5,6]
How do I get it? And it should not be like ["1,2,3,4,5,6"] Because I want to compare the data in:
  $product_id = Product::where('name', 'like','%'.$main.'%')->where('id', $explode_id)->pluck('id');
I got the answer here. Am passing the id that i want to match in URL like
$("input[type='checkbox']").click(function() {
  if ($(this).is(':checked')) {
   var days = $(this).val();
   $.ajax({
        type: "get",
        url: '/getcreatedat',
        data: { 'days': days },
        success: successFunc,
            error: errorFunc
        });
        function successFunc(data, status) {
          var pageURL = $(location).attr("href");
          window.location.href = pageURL+ '/' +data;
        }   
        function errorFunc(xhr, error) {
             console.log(error);
        }
    }
});
The next time I click the function: url passing the id's double the time
@Kayal try it with array_map() with inval like below:
<?php
    $explode_id = array_map('intval', explode(',', $request->data));
                        You can just json_decode it.
$explode_id = json_decode($request->data, true);
Also, if you're trying to do a IN() condition, you can use:
->whereIn('id', $explode_id);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With