title: Laravel trying to get property of non-object in an object
body: <p>Simple code will not work! I keep getting the error <strong>Trying to get property of non-object</strong> on the line with the if statement. I tried accessing this like an array I get a message saying it can't access a stdClass as an Array.</p>
  
  <pre><code>    public function isAllowed($perm)
      {
         $cando = 0;
         $groups = DB::table('group_user')-&gt;where('user_id', $this-&gt;id)-&gt;get();
  
         foreach ($groups as $mygroup)
         {
            $group_can = DB::table('group_permission')-&gt;where([
              ['permission_id', $permission-&gt;id],
              ['group_id', $mygroup-&gt;group_id]
            ])-&gt;first();
  
            $setting = $group_can-&gt;setting; // Error returns for this line // 
  
            if ($setting &gt; $cando)
            {
              $cando = $setting;
            }
          }
       }
  </code></pre>
  
  <p>print_r, var_dump, and dd of $group_can give this:</p>
  
  <pre><code>stdClass Object
  (
      [group_id] =&gt; 1
      [permission_id] =&gt; 50
      [setting] =&gt; 1
  )
  object(stdClass)#555 (3) { ["group_id"]=&gt; int(1) ["permission_id"]=&gt; int(50) ["setting"]=&gt; int(1) }
  {#555 ▼
    +"group_id": 1
    +"permission_id": 50
    +"setting": 1
  }
  </code></pre>
  
  <p>Using $setting = $group_can->setting; returns the error <strong>Trying to get property of non-object</strong></p>
  
  <p>Using $setting = $group_can['setting']; returns the error <strong>Cannot use object of type stdClass as array</strong></p>
  
  <p>The details of the laravel error are: </p>
  
  <blockquote>
    <p>at HandleExceptions->handleError(8, 'Trying to get property of non-object', '/home/mwsubmissions/public_html/jon/MWSubmissionManager/app/User.php', 91, array('perm' => 'manage.projects', 'cando' => 1, 'groups' => object(Collection), 'permission' => object(stdClass), 'mygroup' => object(stdClass), 'group' => null, 'group_can' => null, 'setting' => 1))</p>
  </blockquote>
  
  <p><strong>EDIT</strong>
  I removed the first part of the code that I was having errors with and then got to this, another example of the same thing, but using a smaller object and this line is more important than the last was. All details updated.</p>