Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Osho's avatar
Level 1

500 Internal Server Error

Error Log

[2020-10-30 18:56:53] local.ERROR: Illegal operator and value combination. {"userId":5,"exception":"[object] (InvalidArgumentException(code: 0): Illegal operator and value combination. at /Applications/XAMPP/xamppfiles/htdocs/afiaprime/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:754)
[stacktrace]

Controller

public function productsCat(Request $request){
        
        $cat_id = $request->cat_id;
        // dd(count($request->price));
        $pricemax= $request->max_price;
        $pricemin= $request->min_price;
        $search= $request->search;

        // price are array
        if($cat_id!="" && $pricemax!="0" && $search!=""){
        //   $price = explode("-",$request->price);
        $pricemax= $request->max_price;
        $pricemin= $request->min_price;
        $search= $request->search;
 
           $start = $pricemin;
           $end = $pricemax;
 
           //echo "both are selected";
           $data = DB::table('products')
           ->join('product_categories','product_categories.id','products.categories_id')
           ->where('products.categories_id',$cat_id)
           ->where('products.price', ">=", $start)
           ->where('products.price', "<=", $end)
           ->where('products.p_name',$search)
           ->get();
 
        }
        else if($pricemax!="0"){
        //   $price = explode("-",$request->price);
        $pricemax= $request->max_price;
        $pricemin= $request->min_price;

          $start = $pricemin;
          $end = $pricemax;
 
          //echo "price is selected";
          $data = DB::table('products')
          ->join('product_categories','product_categories.id','products.categories_id')
          ->where('products.price', ">=", $start)
          ->where('products.price', "<=", $end)
          ->get();
 
        }
        else if($cat_id!=""){
          //echo "cat is selected";
          $data = DB::table('products')
          ->join('product_categories','product_categories.id','products.categories_id')
          ->where('products.categories_id',$cat_id)
          ->get();
        }
        else{
          //echo "nothing is slected";
          return "<h1 align='center'>Please select atleast one filter from dropdown</h1>";
 
        }
 
        if(!$data){
            echo "<h1 align='center'>no products found under this Category</h1>";
          }else{
          return view('frontEnd.produt-category',[
            'data' => $data, 'catByUser' => $data[0]->cat_name
          ]);
      }
 
     }
0 likes
12 replies
Osho's avatar
Level 1
[2020-10-30 19:12:09] local.ERROR: Illegal operator and value combination. {"userId":5,"exception":"[object] (InvalidArgumentException(code: 0): Illegal operator and value combination. at /Applications/XAMPP/xamppfiles/htdocs/afiaprime/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:754)
[stacktrace]
Osho's avatar
Level 1

I am trying to filter from my request submitted

my blade

<div class="contact-container" style="align-items: flex-start;">
        <div class="form-container lcontact-form" style="width: 100%;">
            <h3 style="margin-bottom: revert; margin-top:12px;">Filter Category</h3>
                <div style="display: inline-block; margin-top:12px; text-align: center;">
                    <input type="text" id="catID" value="{{$catByUser}}" hidden/>
                    <input type="number" id="minpriceID" min="0" class="form-control" style="margin: inherit;" placeholder="Min Price">
                    <input type="number" id="maxpriceID" min="0" class="form-control" style="margin: inherit;" placeholder="Max Price">
                    <input type="text" id="search" class="form-control" style="margin: inherit;" placeholder="search product by name">
                    <div style="margin-top:inherit;">
                        <button class="login-btn form-control" id="findBtn" style="margin: inherit; border-left: inset;"> <span class="fas fa-filter"></span> Filter</button>
                    </div>
                </div>
        </div>
        <div class="gender-clothing">
            <div class="title-row">
                <div class="main-title">
                <h3 style="font-size: xx-large;">{{$catname->name}} Category</h3>
                </div>
            </div>
            <div class="cloth-row" id="productData">
            @if(count($data)=="0")
                <h1 align="center" style="margin-top:20px">
                    No products found under
                <b style="color:red">{{$catByUser}} </b>
                    Category
                </h1>
            @elseif (count($data)!="0")
                    @foreach($data as $p)
                        <div class="cloth">
                            <div class="card">
                            <img src="/products/large/{{$p->image}}" alt="{{$p->image}}" style="width:100%">
                            <h1 style="margin-top: revert;">{{$p->p_name}}</h1>
                            <br>
                            <p class="price" style="color:#0d6cb3;">NGN {{$p->price}}</p>
                            <br>
                            <p><a href="/product-detail/{{$p->id}}/{{$p->slug}}"><button>Explore</button></a></p>
                            </div>
                        </div>
                    @endforeach
            @endif
            </div>
        </div>
    </div>

<script>
$(document).ready(function(){
  $("#findBtn").click(function(){
    var cat = $("#catID").val();
    var minprice = $('#minpriceID').val();
    var maxprice = $('#maxpriceID').val();
    var search = $('#search').val();
    
    $.ajax({
      type: 'get',
      dataType: 'html',
      url: '{{url('/productsCat')}}',
      data: 'cat_id=' + cat + 'min_price=' + minprice + 'max_price=' + maxprice + 'search=' + search,
      success:function(response){
        console.log(response);
        $("#productData").html(response);
      }
    });
  });
});
</script>

my route

Route::get('/selected-category/{id}/{slug}', 'SelectedCategoryController@show')->middleware('auth');
Route::get('selected-category/{id}/{slug}','SelectedCategoryController@show');
Route::get('productsCat','SelectedCategoryController@productsCat');

my controller

public function productsCat(Request $request){
        
        $cat_id = $request->cat_id;
        // dd(count($request->price));
        $pricemax= $request->max_price;
        $pricemin= $request->min_price;
        $search= $request->search;

        // price are array
        if($cat_id!="" && $pricemax!="0" && $search!=""){
        //   $price = explode("-",$request->price);
        $pricemax= $request->max_price;
        $pricemin= $request->min_price;
        $search= $request->search;
 
           $start = $pricemin;
           $end = $pricemax;
 
           //echo "both are selected";
           $data = DB::table('products')
           ->join('product_categories','product_categories.id','products.categories_id')
           ->where('products.categories_id',$cat_id)
           ->where('products.price', ">=", $start)
           ->where('products.price', "<=", $end)
           ->where('products.p_name',$search)
           ->get();
 
        }
        else if($pricemax!="0"){
        //   $price = explode("-",$request->price);
        $pricemax= $request->max_price;
        $pricemin= $request->min_price;

          $start = $pricemin;
          $end = $pricemax;
 
          //echo "price is selected";
          $data = DB::table('products')
          ->join('product_categories','product_categories.id','products.categories_id')
          ->where('products.price', ">=", $start)
          ->where('products.price', "<=", $end)
          ->get();
 
        }
        else if($cat_id!=""){
          //echo "cat is selected";
          $data = DB::table('products')
          ->join('product_categories','product_categories.id','products.categories_id')
          ->where('products.categories_id',$cat_id)
          ->get();
        }
        else{
          //echo "nothing is slected";
          return "<h1 align='center'>Please select atleast one filter from dropdown</h1>";
 
        }
 
        if(!$data){
            echo "<h1 align='center'>no products found under this Category</h1>";
          }else{
          return view('frontEnd.produt-category',[
            'data' => $data, 'catByUser' => $data[0]->cat_name
          ]);
      }
 
     }
Osho's avatar
Level 1

I applied it for all three

MichalOravec's avatar

Change this

->join('product_categories','product_categories.id','products.categories_id')

to this in your controller, you have it there tree times.

->join('product_categories', 'product_categories.id', '=', 'products.categories_id')

Is it a problem?

Osho's avatar
Level 1

Applied but still getting the same error in error log

public function productsCat(Request $request){
        
        $cat_id = $request->cat_id;
        // dd(count($request->price));
        $pricemax= $request->max_price;
        $pricemin= $request->min_price;
        $search= $request->search;

        // price are array
        if($cat_id!="" && $pricemax!="0" && $search!=""){
        //   $price = explode("-",$request->price);
        $pricemax= $request->max_price;
        $pricemin= $request->min_price;
        $search= $request->search;
 
           $start = $pricemin;
           $end = $pricemax;
 
           //echo "both are selected";
           $data = DB::table('products')
           ->join('product_categories','product_categories.id', '=', 'products.categories_id')
           ->where('products.categories_id',$cat_id)
           ->where('products.price', ">=", $start)
           ->where('products.price', "<=", $end)
           ->where('products.p_name',$search)
           ->get();
 
        }
        else if($pricemax!="0"){
        //   $price = explode("-",$request->price);
        $pricemax= $request->max_price;
        $pricemin= $request->min_price;

          $start = $pricemin;
          $end = $pricemax;
 
          //echo "price is selected";
          $data = DB::table('products')
          ->join('product_categories','product_categories.id', '=', 'products.categories_id')
          ->where('products.price', ">=", $start)
          ->where('products.price', "<=", $end)
          ->get();
 
        }
        else if($cat_id!=""){
          //echo "cat is selected";
          $data = DB::table('products')
          ->join('product_categories','product_categories.id', '=', 'products.categories_id')
          ->where('products.categories_id',$cat_id)
          ->get();
        }
        else{
          //echo "nothing is slected";
          return "<h1 align='center'>Please select atleast one filter from dropdown</h1>";
 
        }
 
        if(!$data){
            echo "<h1 align='center'>no products found under this Category</h1>";
          }else{
          return view('frontEnd.product-category',[
            'data' => $data, 'catByUser' => $data[0]->cat_name
          ]);
      }
 
     }
MichalOravec's avatar

Some variable is null which you are using in where statement.

So check them with dd();

dd($cat_id, $start, $end, $search);

By the way for what you are doing something like this

$pricemin= $request->min_price;
$search= $request->search;
 
$start = $pricemin;
$end = $pricemax;
1 like
Osho's avatar
Level 1

I got this

"2min_price=90max_price=100search=another"
null
null
null

I think the first value 2min_price=90max_price=100search=another is the cat_id. it's mean't to be just 2 not the result it is giving. all the results are combined in cat_id. what do I do?

MichalOravec's avatar

In jQuery change this line

data: 'cat_id=' + cat + 'min_price=' + minprice + 'max_price=' + maxprice + 'search=' + search

to

data: {
    cat_id: cat,
    min_price: minprice,
    max_price: maxprice,
    search: search
}
1 like
Osho's avatar
Level 1

Thanks, I'm getting this error now

[2020-10-31 22:24:02] local.ERROR: Undefined offset: 0 {"userId":5,"exception":"[object] (ErrorException(code: 0): Undefined offset: 0 at /Applications/XAMPP/xamppfiles/htdocs/afiaprime/vendor/laravel/framework/src/Illuminate/Support/Collection.php:1362)
[stacktrace]
Osho's avatar
Level 1
[2020-11-02 00:31:13] local.ERROR: Undefined offset: 0 {"userId":5,"exception":"[object] (ErrorException(code: 0): Undefined offset: 0 at /Applications/XAMPP/xamppfiles/htdocs/afiaprime/vendor/laravel/framework/src/Illuminate/Support/Collection.php:1362)
[stacktrace]

This is the error I'm getting now

Please or to participate in this conversation.