title: Laravel 5.3 Check if result exist
body: <p>I'm having trouble getting this thing to work. Basically this function is called once I click the delete button of an user config. Users can have multiple configs. What happens is that once I delete a config it looks for another one, if found it sets that as the current profile. If not it should set the config_done back to 0. the first bit works fine but if <code>$firstProfile</code> returns nothing, instead of entering the <code>else</code> it returns me an error..</p>
  
  <p>code:</p>
  
  <pre><code>public function delete(UserConfig $config) {
      $user = Auth::user();
      $uid = $user-&gt;id;
  
      if ($uid == $config-&gt;user_id) {
  
        UserConfig::where('id', $config-&gt;id)-&gt;delete();
  
        $firstProfile = UserConfig::where('user_id', $uid)-&gt;first()-&gt;id;
  
        if(count($firstProfile)){
          $user = User::find($uid);
          $user-&gt;current_profile = $firstProfile;
          $user-&gt;save();
  
          return view('/settings');
        } else {
          $user = User::find($uid);
          $user-&gt;config_done = 0;
          $user-&gt;save();
  
          return view('/home');
        }
      }
    }
  </code></pre>
  
  <p>error: </p>
  
  <pre><code>ErrorException in UserConfigController.php line 100:
  Trying to get property of non-object
  in UserConfigController.php line 100
  at HandleExceptions-&gt;handleError('8', 'Trying to get property of non-object', '/Users/jordykoppen/git/beef-monitor/app/Http/Controllers/UserConfigController.php', '100', array('config' =&gt; object(UserConfig), 'user' =&gt; object(User), 'uid' =&gt; '1')) in UserConfigController.php line 100
  </code></pre>
  
  <p>Keep in mind that I'm very new to Laravel and the whole MVC environment. </p>