0
votes

Si condition dans la requête Laravel

Un peu de temps Certaines variables sont nulles, alors comment vérifier la variable n'est pas nulle et s'applique directement à la requête

 $fiter_products = DB::table('products')->DISTINCT('modalid')->DISTINCT('brandid')->select('rimdiameter','modalid','modalname1','modalname2','image1','brand','minprice','maxprice')->where('hubbore','>=',$centre_bore)->where('boltpattern',$boltptn)->where('rimdiameter', $diameter)->where('rimwidth', $width)->where('rimwidthfront', $frontwid)->where('construction', $construct)->where('modalname2', $color)->where('brand', $brand)->get(); 


0 commentaires

3 Réponses :


0
votes

Vous pouvez utiliser la méthode WHERENOOTNULL ('Champ) . Du Docs :

La méthode WherenoNull vérifie que la valeur de la colonne n'est pas null


0 commentaires

0
votes
$product = DB::table('products')->DISTINCT('modalid')->DISTINCT('brandid')->select('rimdiameter','modalid','modalname1','modalname2','image1','brand','minprice','maxprice');

if(isset($centre_bore)){
    $product->where('hubbore','>=',$centre_bore);
}

if(isset($boltptn)){
    $product->where('boltpattern',$boltptn);
}

if(isset($diameter)){
    $product->where('rimdiameter', $diameter);
}

if(isset($width)){
    $product->where('rimwidth', $width);
}

if(isset($frontwid)){
    $product->where('rimwidthfront', $frontwid);
}

if(isset($construct)){
    $product->where('construction', $construct);
}

if(isset($color)){
    $product->where('modalname2', $color);
}

if(isset($brand)){
    $product->where('brand', $brand);
}     

$fiter_products = $product->get(); 

0 commentaires