mercredi 13 mars 2019

Laravel Eloquent : Getting object instead of array

Trying to get a hotel in detail for hotel management API, in which for some hotels, getting

$hotel->rooms

as object and for some as array. The eloquent query in Hotel model as below.

public function detail($hotelid) { 
    return $this->with(['rooms'])->find($hotelid);
}

response

{
    "id":"id",
    "name":"name",
    "rooms":{
        "1":{},
        "2":{}
    }       
}

{
    "id":"id",
    "name":"name",
    "rooms":[
        {},
        {},
    ]       
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire