Fill Eloquent model with extra data from API call

  api, eloquent, laravel-7, php

I have an API that return the detail of my data. the detail data is stored in another server which is why i retrieve the data using API.

{
"id": "1234",
"nomor": "123457",
"post": null
}

I append the API result data to eloquent model using this configuration

class ABR extends Model 
{

protected $appends = ['moredata'];

function getMoredataAttribute() {
    $res = Http::get(link to api);
    $data = json_decode($res->body());
    return $data;
}

}

I successfully retrieve and append the extra data from API, but i am not happy with the load time. is there something that can be done to reduce the load time?

Source: Ask PHP

LEAVE A COMMENT