title: Laravel Error: Trying to get property of non-object when accessing via first() method
body: <p>I am using laravel 5.6 with PHP 7.1.</p>
  
  <p>Laravel throws <code>ErrorException Trying to get property of non-object</code>  when I try to access property of the post which is retrieved using eloquent <code>first()</code> method. </p>
  
  <pre><code>$post = Blog::select('id', 'title', 'slug')-&gt;where('slug', $slug)-&gt;first(); //slug is unique column in database
  $post-&gt;title; //this line cause the error
  </code></pre>
  
  <p>However, If I use <code>find()</code> method, it works without any error.</p>
  
  <pre><code>$post = Blog::select('id', 'title', 'slug')-&gt;find($primarykey);
  $post-&gt;title; //No error
  </code></pre>
  
  <p>Since, I can not use the second method, what is the best possible way to access these properties when modal is retrieved by <code>first()</code> method?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>When I do <code>dd($post)</code> with these 2 methods, I see exact result.<br>
  Also the error is getting logged in <code>laravel.log</code> file and I can see the page without any problem. This happen only when I use <code>first()</code> method.</p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>Here is my exact code:</p>
  
  <pre><code>$viewData['resource'] = Resource::select('id', 'resource_category_id', 'name', 'descp', 'seo_title', 'seo_keywords', 'seo_descp', 'dl_type', 'download', 'thumb', 'image', 'dl_count', 'updated_at')-&gt;with(['category' =&gt; function($q){
          $q-&gt;select('id', 'name', 'slug', 'parent_id');
      }])-&gt;where('slug', $slug)-&gt;first();
  $id = $viewData['resource']-&gt;id; // this line throw error, line 126
  </code></pre>
  
  <p><code>local.ERROR: Trying to get property of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property of non-object at E:\\websites\\couponclone\\app\\Http\\Controllers\\ResourceController.php:126)</code></p>