title: Call to a member function first() on null in laravel resource
body: <p>i try to build a customized response in my resource like this:</p>
  
  <pre class="lang-php prettyprint-override"><code>    class ApplicationResource extends JsonResource
      {
          /**
           * Transform the resource into an array.
           *
           * @param  \Illuminate\Http\Request $request
           * @return array
           */
          public function toArray($request)
          {
              return [
                  'id' =&gt; $this-&gt;id,
                  'sort'=&gt; $this-&gt;sort,
                  'is_seen' =&gt; $this-&gt;is_seen,
                  'name' =&gt; $this-&gt;name,
                  'position' =&gt; $this-&gt;position,
                  'company' =&gt; $this-&gt;company,
                  'education' =&gt; $this-&gt;education,
                  'degree' =&gt; $this-&gt;degree,
                  'phone' =&gt; $this-&gt;phone,
                  'university' =&gt; $this-&gt;university,
                  'cv_folder_id' =&gt; $this-&gt;cv_folder_id,
                  'cv' =&gt; route('applications.cvShow', ['candidateCv' =&gt; $this-&gt;candidate_cv]),
                  'comments'=&gt;   ApplicationCommentsResource::collection($this-&gt;applicationComments),
                  'ratingFields'=&gt;   ApplicationRatingsResource::collection($this-&gt;applicationRatings()-&gt;get()),
                  'jobPostRatingFields' =&gt;   JobPostRatingFieldsResource::collection($this-&gt;jobPost-&gt;jobPostRatingFields),
  
              ];
          }
      }
  </code></pre>
  
  <p>but i just get errors. the error i get is: </p>
  
  <blockquote>
    <p>Call to a member function first() on null</p>
  </blockquote>
  
  <p>i dont know how to build my response that if the collection is empty i dont get any error?</p>