title: return rows in laravel that are not empty
body: <p>I have the following output that I am getting from the laravel and I am inserting them in to selectbox as an option. But for the <code>lunch option</code> my last options are empty. How can I return rows in laravel that are not empty?</p>
  
  <blockquote>
    <p>{"id":18,"guest_origin":"Bulgaria","heard_where":"","staying_at":"","lunch_option":"Cheese"},{"id":19,"guest_origin":"Chech
    Republic","heard_where":"","staying_at":"","lunch_option":"Chicken"},{"id":20,"guest_origin":"China","heard_where":"","staying_at":"","lunch_option":"Ham"},{"id":21,"guest_origin":"Denmark","heard_where":"","staying_at":"","lunch_option":""},{"id":22,"guest_origin":"Finland","heard_where":"","staying_at":"","lunch_option":""},{"id":23,"guest_origin":"Israel","heard_where":"","staying_at":"","lunch_option":""},{"id":24,"guest_origin":"Malaysia","heard_where":"","staying_at":"","lunch_option":""},{"id":25,"guest_origin":"Norway","heard_where":"","staying_at":"","lunch_option":""},</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/F7zdS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/F7zdS.png" alt="enter image description here"></a></p>
  
  <p>controller.php</p>
  
  <pre><code>function getComboselect( Request $request)
  {
      if($request-&gt;ajax() == true &amp;&amp; \Auth::check() == true)
      {
          $param = explode(':',$request-&gt;input('filter'));
          $parent = (!is_null($request-&gt;input('parent')) ? $request-&gt;input('parent') : null);
          $limit = (!is_null($request-&gt;input('limit')) ? $request-&gt;input('limit') : null);
          $rows = $this-&gt;model-&gt;getComboselect($param,$limit,$parent);
          $items = array();
          $fields = explode("|",$param[2]);
          foreach($rows as $row) 
          {
              $value = "";
              foreach($fields as $item=&gt;$val)
              {
                  if($val != "") $value .= $row-&gt;{$val}." ";
              }
              $items[] = array($row-&gt;{$param['1']} , $value);     
          }
      return json_encode($items);     
      } 
  </code></pre>
  
  <p>Model.php</p>
  
  <pre><code>static function getComboselect( $params , $limit =null, $parent = null)
  {   
      $limit = explode(':',$limit);
      $parent = explode(':',$parent);
      if(count($limit) &gt;=3)
      {
          $table = $params[0]; 
          $condition = $limit[0]." `".$limit[1]."` ".$limit[2]." ".$limit[3]." "; 
          if(count($parent)&gt;=2 )
          {
              $row =  \DB::table($table)-&gt;where($parent[0],$parent[1])-&gt;get();
               $row =  \DB::select( "SELECT * FROM ".$table." ".$condition ." AND ".$parent[0]." = '".$parent[1]."'");
          } else  {
             $row =  \DB::select( "SELECT * FROM ".$table." ".$condition);
          }        
      }else{
          $table = $params[0]; 
          if(count($parent)&gt;=2 )
          {
              $row =  \DB::table($table)-&gt;where($parent[0],$parent[1])-&gt;get();
          } else  {
              $row =  \DB::table($table)-&gt;get();
          }              
      }
      return $row;
  }
  </code></pre>
  
  <p>This code is using <a href="http://carlosdeoliveira.net/jcombo/?lang=en" rel="noreferrer">http://carlosdeoliveira.net/jcombo/?lang=en</a>. If you look up to the example on the project link you will see that it is using parent (state) to list the child (cities) for listings. I am not using the parent so nothing is assinged to variables $parent[0] and $parent[ 1 ], thus nothing to worry about but for the rest, I will try to post each result below so, you would have a better idea. My understanding is that the model.php is passing the data to controllers.php using  <code>$row =  \DB::table($table)-&gt;get();</code> If you look to the screenshot, you will see that I have more then 1 column to list the options. I cannot write a single column name there if I write <code>$row = \DB::table($table)-&gt;whereRaw('lunch &lt;&gt; ""')-&gt;get();</code> this brings the options until the Id 4. In this case Holland is not in the option list for guest origin. </p>
  
  <p>Once the model.php passes <code>$row</code> to controllers.php, It' returning the following results for each variable.</p>
  
  <pre><code>print_r($row);
  </code></pre>
  
  <blockquote>
    <p>stdClass Object ( [id] => 48 [guest_origin] => Other [heard_where] =>
    [staying_at] => [lunch_option] => )</p>
  </blockquote>
  
  <pre><code>print_r($rows);
  </code></pre>
  
  <blockquote>
    <p>Illuminate\Support\Collection Object ( [items:protected] => Array (
    [0] => stdClass Object ( [id] => 1 [guest_origin] => Western Australia
    [heard_where] => Wildsights Office [staying_at] => Wildsights Villas
    [lunch_option] => Chicken ) <a href="https://i.stack.imgur.com/F7zdS.png" rel="noreferrer">1</a> => stdClass Object ( [id] => 2
    [guest_origin] => Rest of Australia [heard_where] => Brochure
    [staying_at] => Wildsights Beach Units [lunch_option] => Cheese ) [2]
    => stdClass Object ( [id] => 3 [guest_origin] => Germany &amp; Austria [heard_where] => Sign [staying_at] => Bay Lodge Backpackers
    [lunch_option] => Ham ) [3] => stdClass Object ( [id] => 4
    [guest_origin] => UK &amp; Eire [heard_where] => Word of Mouth
    [staying_at] => Blue Dolphin Caravan Park [lunch_option] => Tuna )</p>
  </blockquote>
  
  <pre><code>print_r($fields);
  </code></pre>
  
  <blockquote>
    <p>Array ( [0] => staying_at )</p>
  </blockquote>
  
  <pre><code>print_r($value); 
  </code></pre>
  
  <p>prints nothing</p>
  
  <pre><code>print_r($items);
  </code></pre>
  
  <blockquote>
    <p>[8] => Array ( [0] => Shark Bay Holiday Cottages <a href="https://i.stack.imgur.com/F7zdS.png" rel="noreferrer">1</a> => Shark Bay
    Holiday Cottages ) [9] => Array ( [0] => Shark Bay Hotel <a href="https://i.stack.imgur.com/F7zdS.png" rel="noreferrer">1</a> => Shark
    Bay Hotel )</p>
  </blockquote>
  
  <p>Hope it is clear and you can help me to filter the empty rows before it goes into loop.</p>