mercredi 29 mai 2019

How to mapping nested json to database in laravel php?

I retrieve B employee data from API server and return Json data that contain the employee's position and also the subordinate of the B employee also with the subordinate from that B employee's subordinate. The JSON data also return the position_head that means the boss of B Employee. The JSON look like this,

{
    "msg": "OK",
    "DATA": {
        "id": "2",
        "name": "DEDE",
        "email": "dede@mail.com",
        "username": "dede@mail.com",
        "jabatan": "Chief Executive Officer",
        "bidang": null,
        "picture": "https://web.com/resource/2.png",
        "subordinate": [
            {
                "position_name": "GROUP HEAD  FINANCE & GENERAL AFFAIR",
                "staffs": [
                    {
                        "staff_name": "BIMA",
                        "staff_id": "3",
                        "staff_code": "bima@mail.com"
                    }
                ],
                "children": [
                    {
                        "position_name": "OPERATIONS MANAGER",
                        "staffs": [
                            {
                                "staff_name": "MONA",
                                "staff_id": "6",
                                "staff_code": "mona@mail.com"
                            }
                        ]
                    },
                    {
                        "position_name": "ACCOUNTS EXECUTIVE",
                        "staffs": [
                            {
                                "staff_name": "RINA",
                                "staff_id": "14",
                                "staff_code": "rina@mail.com"
                            },
                            {
                                "staff_name": "MIKE",
                                "staff_id": "5",
                                "staff_code": "mike@mail.com"
                            }
                        ]
                    },
                    {
                        "position_name": "HEAD OF FINANCE & ACCOUNTING",
                        "staffs": [
                            {
                                "staff_name": "Testing",
                                "staff_id": "17",
                                "staff_code": "testing"
                            },
                            {
                                "staff_name": "JOHN",
                                "staff_id": "4",
                                "staff_code": "johb@mail.com"
                            }
                        ]
                    }
                ]
            },
            {
                "position_name": "GROUP HEAD MARKETING & SALES",
                "staffs": [
                    {
                        "staff_name": "LAUREN",
                        "staff_id": "7",
                        "staff_code": "lauren@mail.com"
                    }
                ],
                "children": [
                    {
                        "position_name": "SALES MANAGEMENT",
                        "staffs": [
                            {
                                "staff_name": "LUKE",
                                "staff_id": "10",
                                "staff_code": "luke@mail.com"
                            }
                        ]
                    },
                    {
                        "position_name": "CUSTOMER CARE & CM",
                        "staffs": [
                            {
                                "staff_name": "WALKER",
                                "staff_id": "16",
                                "staff_code": "walker@mail.com"
                            },
                            {
                                "staff_name": "BARN",
                                "staff_id": "15",
                                "staff_code": "barn@mail.com"
                            }
                        ]
                    },
                    {
                        "position_name": "MARKETING & PRODUCT MANAGER",
                        "staffs": [
                            {
                                "staff_name": "SIRENE",
                                "staff_id": "9",
                                "staff_code": "sirene@mail.com"
                            }
                        ]
                    },
                    {
                        "position_name": "MARKET PERFORMANCE ANALYST",
                        "staffs": [
                            {
                                "staff_name": "GLENN",
                                "staff_id": "8",
                                "staff_code": "glenn@mail.com"
                            }
                        ]
                    }
                ]
            }
        ],
        "position_head": null
    }
}

The problem is I want to mapping the data and put it in database table User with this column,

id
position
staff_name
staff_code
parent_staff_id

How to do the task? any help will appreciate



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire