mardi 29 septembre 2015

REST API Laravel: How to return a complex JSON response from an API

I'm a beginner with Laravel and PHP generally and was asked to create an API to get an array of data with an output like this:

"stages": [
                {
                    "id": "1f149fc7-5270-11e5-b3f3-3417ebe4606c",
                    "User": 
                                {
                                    "userId": "262b990f-526f-11e5-b3f3-3417ebe4606c",
                                    "firstName": "Name",
                                    "LastName": "last Name"
                                    "country": 
                                            {
                                                "countryId": 1,
                                                "countryName": "country"
                                            },
                                    "city": "city",
                                    "profilePicPath": "/path/abf115b7_5258_11e5_b3f3_3417ebe4606c/photo.jpeg"
                                },

                    "uploadDate": "2015-09-03 02:15:21",
                    "stageTypeId": "1f149fc7-5270-11e5-b3f3-3417ebe4606c",
                    "stageFilePath": "/path/MjYyYjk5MGYtNTI2Zi0xMWU1LWIzZjMtMzQxN2ViZTQ2MDZj.mp4",
                    "stageFilePhypath": "/path/MjYyYjk5MGYtNTI2Zi0xMWU1LWIzZjMtMzQxN2ViZTQ2MDZj.mp4",
                    "commentsCount":
                                {
                                    "count": 100,
                                },
                    "like":
                                {
                                    "count": 100
                                },

It is like twitter/instagram API where data returned is complete and complex. I have created an API with simple responses but not something like this where I have to get data from all other tables for each array of data that will be returned by the service. Also this would be easy if the data that I'm getting is not an array but for a specific ID. Is there a way can implement getting all data for each result array? Do I need to create 1 complex query to gather every information that I need?

Please help. Any advice, hints, tutorials will be really appreciated.

Thank you very much!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Rd5sc2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire