title: mb_strpos() expects parameter 1 to be string, object given when querying 2 tables in Laravel
body: <p>Ok, so I don't know if this can be done, but I need to combine the results of 2 Where clauses from 2 tables into one variable.</p>
  
  <p>So far I have this working to query one table:</p>
  
  <pre class="lang-php prettyprint-override"><code>$allCompanies = Products::where('category_id', $id-&gt;id)-&gt;groupBy('company_id')-&gt;get();
  </code></pre>
  
  <p>And this for the other:</p>
  
  <pre class="lang-php prettyprint-override"><code>$companies = Company::where('visible', 0)-&gt;get();
  </code></pre>
  
  <p>But is there any way to get them into the same query string? Something like so I can get where the ID matches the ID column in one table AND where visible is 0 in the other?</p>
  
  <p>I tried this:</p>
  
  <pre class="lang-php prettyprint-override"><code>$allCompanies = Products::with('company', function($q){
              $q-&gt;where('visible', 0);
              })-&gt;where('category_id', $id-&gt;id)
              -&gt;groupBy('company_id')-&gt;get();
  </code></pre>
  
  <p>but got this error:</p>
  
  <pre><code>mb_strpos() expects parameter 1 to be string, object given
  </code></pre>
  
  <p>Company Model:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Company extends Model
  {
      public function products()
      {
          return $this-&gt;hasMany('App\Products');
      }
  }
  </code></pre>
  
  <p>Products Model</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Products extends Model
  {
      protected $fillable = [
          'name',
          'description',
          'image',
          'size',
          'price',
          'stock',
          'company_id',
          'category_id'
      ];
      public function category()
      {
          return $this-&gt;belongsTo('App\Categories', 'category_id');
      }
      public function company()
      {
          return $this-&gt;belongsTo('App\Company', 'company_id');
      }
  }
  </code></pre>