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();
3 Réponses :
Vous pouvez utiliser la méthode La méthode WherenoNull vérifie que la valeur de la colonne n'est pas null p>
blockQuote> WHERENOOTNULL ('Champ) CODE>. Du Docs : P>
$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();
Vous pouvez passer une autre fermeture comme troisième paramètre sur le quand a > méthode. Cette fermeture s'exécutera si le premier paramètre évalue comme faux. $fiter_products = DB::table('products')
->DISTINCT('modalid')
->DISTINCT('brandid')
->select('rimdiameter','modalid','modalname1','modalname2','image1','brand','minprice','maxprice')
->when($centre_bore, function($query, $centre_bore) {
$query->where('hubbore','>=',$centre_bore);
})->when($boltptn, function($query, $boltptn) {
$query->where('boltpattern',$boltptn);
})...
qu'est-ce que $ question param param
@andrewghosh $ Query code> est requis-constructeur