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.

> 
> array\_key\_exists(): The first argument should be either a string or an
>  integer.
> 
> 
> 

Here is my method or function.

```
public function getCategories($idService)
{
    $service = Service::findOrFail($idService);
    return $service->categories->get(['id','name']);;
}

```

and here is the defined route.

```
Route::get('service/{service}/categories', 'ServiceController@getCategories');

```

I tried to look and browse for it but can't find any solution at all.