title: Laravel array key exists in get method
body: <p>I am trying to fetch the the id and the name of the categories which is related to my services. A service has many categories and a categories belongs to a services. However when I try to get the id and the name as an array to return it gives me this error.</p>
  
  <blockquote>
    <p>array_key_exists(): The first argument should be either a string or an
    integer.</p>
  </blockquote>
  
  <p>Here is my method or function.</p>
  
  <pre><code>public function getCategories($idService)
  {
      $service = Service::findOrFail($idService);
      return $service-&gt;categories-&gt;get(['id','name']);;
  }
  </code></pre>
  
  <p>and here is the defined route.</p>
  
  <pre><code>Route::get('service/{service}/categories', 'ServiceController@getCategories');
  </code></pre>
  
  <p>I tried to look and browse for it but can't find any solution at all.</p>