mercredi 28 mars 2018

Laravel array key exists in get method

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.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2pPjNVJ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire