mercredi 4 octobre 2017

How to handle null value inside whereIn?

I have the following Query to be executed where $category_id & $industry_id came through ajax request as array. so sometimes $category_id & $industry_id could be null value. So how do avoid that line of statement when the array would be null?

$products = DB::table('users')
               ->join('products','products.auth_id','users.id')
               ->Join('reviews','products.id','reviews.product_id')
               ->select('products.*','users.avatar',DB::raw('(sum(rating)/count(user_id)) as rating'))             
               ->orwhereIn('products.category_id', [$request->get('category_id')])   
               ->orwhereIn('products.industry_id',[$request->get('industry_id')])   
               ->where('products.status','=','1')           
               ->groupBy('reviews.product_id')   
               ->latest()              
               ->get();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire