php - Laravel Build Eloquent Query to fetch data using fillters -
in application have product table 4 different types of filters first step user selects filter frontend via ajax push them session , create array of each type of filters..below code wrote not working expected return results if there no empty array passed in clause want fetch results whatever filter pass in query
filters array
$industrytags = ['agriculture & farming','medical']; $styletags = ['modern','floral']; $orientationtags = []; $colortags = ['red','green'];
query
$updatedproducts = product::wherein('industry', $industrytags)->wherein('style', $styletags)->wherein('orientation', $orientationtags)->wherein('color', $colortags)->get();
its not returning results because 1 of filter type null want query fetches data available filter
try -
$condition = "orientation in ('value1', 'value2', 'value3') or orientation null"; $updatedproducts = product::wherein('industry', $industrytags) ->wherein('style', $styletags) ->whereraw($condition) ->wherein('color', $colortags)->get();
hope you.
Comments
Post a Comment