Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to insert header tags to API Json

Hello im making a GET api in laravel that shows values from database and im trying to make it that the returned json result to have a header tag an example is this public api

https://dummy.restapiexample.com/api/v1/employees

As you can see this api shows the status:success and then data: , this is my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 function getDevice()
    {
        return Client::all();
    }

And this is the result i get in postman:

  data [  //here to have a header
        {
            "id": 1,
            "name": "Mr. Omari Schaefer DVM",
            "email": "kulas.julian@example.net",
            "phone_number": "0697830800",
            "age": "29",
            "salary": "150",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 2,
            "name": "Hattie Brakus",
            "email": "deckow.coby@example.com",
            "phone_number": "0697830800",
            "age": "30",
            "salary": "565",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 3,
            "name": "Sabrina Rosenbaum",
            "email": "kautzer.madison@example.net",
            "phone_number": "0697830800",
            "age": "31",
            "salary": "254",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 4,
            "name": "Ms. Fiona Fritsch",
            "email": "juwan.damore@example.net",
            "phone_number": "0697830800",
            "age": "32",
            "salary": "029",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 5,
            "name": "Michael Dooley",
            "email": "hayes.reinhold@example.org",
            "phone_number": "0697830800",
            "age": "33",
            "salary": "265",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 6,
            "name": "Prof. Kelley Koepp Jr.",
            "email": "kutch.jessie@example.org",
            "phone_number": "0697830800",
            "age": "34",
            "salary": "688",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 7,
            "name": "Herminia McClure PhD",
            "email": "ywillms@example.com",
            "phone_number": "0697830800",
            "age": "35",
            "salary": "103",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 8,
            "name": "Morton Considine",
            "email": "lesly.pfeffer@example.com",
            "phone_number": "0697830800",
            "age": "36",
            "salary": "804",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 9,
            "name": "Katlyn Muller",
            "email": "peter93@example.net",
            "phone_number": "0697830800",
            "age": "37",
            "salary": "695",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 10,
            "name": "Wilber Stehr",
            "email": "bmckenzie@example.net",
            "phone_number": "0697830800",
            "age": "38",
            "salary": "941",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 11,
            "name": "Test User",
            "email": "test@example.com",
            "phone_number": "0697830800",
            "age": "60",
            "salary": "448",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        }
    ]

What im trying to do is:

    [
        {
            "id": 1,
            "name": "Mr. Omari Schaefer DVM",
            "email": "kulas.julian@example.net",
            "phone_number": "0697830800",
            "age": "29",
            "salary": "150",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 2,
            "name": "Hattie Brakus",
            "email": "deckow.coby@example.com",
            "phone_number": "0697830800",
            "age": "30",
            "salary": "565",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 3,
            "name": "Sabrina Rosenbaum",
            "email": "kautzer.madison@example.net",
            "phone_number": "0697830800",
            "age": "31",
            "salary": "254",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 4,
            "name": "Ms. Fiona Fritsch",
            "email": "juwan.damore@example.net",
            "phone_number": "0697830800",
            "age": "32",
            "salary": "029",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 5,
            "name": "Michael Dooley",
            "email": "hayes.reinhold@example.org",
            "phone_number": "0697830800",
            "age": "33",
            "salary": "265",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 6,
            "name": "Prof. Kelley Koepp Jr.",
            "email": "kutch.jessie@example.org",
            "phone_number": "0697830800",
            "age": "34",
            "salary": "688",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 7,
            "name": "Herminia McClure PhD",
            "email": "ywillms@example.com",
            "phone_number": "0697830800",
            "age": "35",
            "salary": "103",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 8,
            "name": "Morton Considine",
            "email": "lesly.pfeffer@example.com",
            "phone_number": "0697830800",
            "age": "36",
            "salary": "804",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 9,
            "name": "Katlyn Muller",
            "email": "peter93@example.net",
            "phone_number": "0697830800",
            "age": "37",
            "salary": "695",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 10,
            "name": "Wilber Stehr",
            "email": "bmckenzie@example.net",
            "phone_number": "0697830800",
            "age": "38",
            "salary": "941",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        },
        {
            "id": 11,
            "name": "Test User",
            "email": "test@example.com",
            "phone_number": "0697830800",
            "age": "60",
            "salary": "448",
            "created_at": "2023-02-17T08:36:00.000000Z",
            "updated_at": "2023-02-17T08:36:00.000000Z"
        }
    ]

>Solution :

function getDevice() 
{
 return ['data' => 
 Client::all(),
 };
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading