php - laravel 5 search query issue -


i need search filtering different columns db table, filtering columns groupa, groupb , groupc, each column has 1 of following values high, low, moderate in db table

but front end user have anther value called "none", value not contain in database.

this current query

  public function show($groupa, $groupb, $groupc)     {         $fodmaps = fodmap::where('groupa', '=', $groupa)->where('groupb', '=', $groupb)->where('groupc', '=', $groupc)->get();         return $fodmaps;       } 

what want if user search value not contain in db (high/low/moderate) should search other columns except 1 have unmatching values

ex: http://url/api/fodmap/groupa=low/groupb=low/groupc=high

if user enter above way should display results according values

but if user inputs following

http://url/api/fodmap/groupa=low/groupb=low/groupc=none

since "none" value in groupc column not exit should search other 2 columns without considering value of groupc

please advice

you can add query condition dynamically this.

      public function show($groupa, $groupb, $groupc)     {         $query = fodmap::query();         if ($groupa !== 'none') {           $query->where('groupa', '=', $groupa)         }          if ($groupb !== 'none') {           $query->where('groupb', '=', $groupb)         }          if ($groupc !== 'none') {           $query->where('groupc', '=', $groupc)         }          return $query->get();     }  

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -