jeudi 21 février 2019

Migrating from FuelPHP to Laravel: problem with one response

i'm migrating an old project from fuel to laravel and i'm having trouble with the response to one of the requests. The issue is, i need the response from laravel to be exactly the same as it was in fuel, because i already have the app in iOS and Android and having the same responses means i only need to change the endpoints. I can't seem to replicate the response here:

  • FuelPHP code and response:

        $belongs = Model_Belong::find('all',array(
            'where'=>array(
                array('id_user',$id_user),
            ),
        ));
    
    return $this->createResponse(200, 'List', $belongs);
    *****RESPONSE****
    {
    "code": 200,
    "message": "List",
    "data": {
        "[1][1]": {
            "id_user": 1,
            "id_group": 1
        },
        "[1][2]": {
            "id_user": 1,
            "id_group": 2
        },
        "[1][3]": {
            "id_user": 1,
            "id_group": 3
        }
    }
    }
    
    
  • Laravel code and response:

        $belongs = Belong::where('id_user', $id_user)
                    ->get();
    
    return $this->createResponse(200, 'List', $belongs);
    *****RESPONSE*****
    {
    "code": 200,
    "message": "List",
    "data": [
        {
            "id_user": 1,
            "id_group": 1,
        },
        {
            "id_user": 1,
            "id_group": 2,
        },
        {
            "id_user": 1,
            "id_group": 3,
        }
    ]
    }
    
    

Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire