Someone who can help please?
Aug 5, 2022
13
Level 1
Compare data from two different sources
Im trying to compare two same keys from different sources (API and sql table) like expenses['vat'] and $phpArray['vat'] and when matching that then fetch only matched data to blade from $expenses query
also want have the ability on matched data to make sql updates to some values from matched @phpArray to $expenses
Is it difficult that? now the test i do i get error: Array to string conversion
Here is the code:
$xmlObject = simplexml_load_string($response);
$json = json_encode($xmlObject);
$phpArray = json_decode($json, true);
$expenses = Expenses::query()->get();
$differenceArray = array_diff($phpArray,$expenses);
dd($differenceArray);
Level 102
Ok so you want every row that matches a vat
Something like this
$vats = collect($phpArray)->pluck('vat');
$expenses = Expenses::query()->whereIn('vat', $vats)->get();
Edit: oh it needs to match on 3 columns. Is that a unique key, those 3 column?
1 like
Please or to participate in this conversation.