Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cib88's avatar
Level 2

Exclude HTTP API array data from results if entry is already in DB

Hello,

I'm calling a JSON API via HTTP then returning the data to my view. Within the view, there is the option to add an item from the API to a DB. I've got this working fine. The bit I'm unsure how to do or approach is excluding the DB entries from showing when I call the API again.

Here's my controller

public function listTopicsFromAPI()
{

    $response = Http::get('https://example.com/topics.json/search');
    $topics = $response->json();

    return view('admin.approve-topics', compact('topics'));
    
}

At some point in this function, I'm guessing I need to check my DB and compare to the API then exclude the items before presenting them back to the user.

The data returned from the API is an array of arrays and I need to check against the Title. I've removed all the junk from the API dump so there's less to read for you.

array:25 [▼
  0 => array:21 [▼
    "Id" => "Topic title",
    "Title" => "Topic title"
  ]
]

Is array_filter the best approach?

0 likes
2 replies
cib88's avatar
Level 2

I didn't even know Arr::where was a thing. Thanks, I'll give this a go now.

1 like

Please or to participate in this conversation.