use collection function at helpers https://laravel.com/docs/5.6/eloquent-collections
Code Update for PHP 7
Some time ago in a system I created, I did a unified deposit check, it just checked if an address made the deposit and then added the balance amount and the history.
Now I'm creating another system, however, using Laravel 5.6 and I'm rewriting some codes, but I do not know how to do all of the caches instead of just 1. I need to know how to do a coding with FOR or FOREACH to check all at once.
Old page.
<?php
require_once 'vlogin.php';
require_once 'config/configDB.php';
require_once 'api/block_io.php';
require_once 'certific.php';
$apiKey = '';
$pin = '';
$version = 2;
$block_io = new BlockIo($apiKey, $pin, $version);
try {
$addressBtcLabel = $block_io->get_address_by_label(array('label' => $nick));
$addressDepositBtc = $addressBtcLabel->data->address;
$checkdeposit = $block_io->get_transactions(array('type' => 'received', 'addresses' => $addressDepositBtc));
if ($checkdeposit->status = "success" && $checkdeposit->data->txs[0]->confirmations >= 2) {
//criação de variaveis menores
$statusCheck = $checkdeposit->status;
$txidCheck = $checkdeposit->data->txs[0]->txid;
$confirmationsCheck = $checkdeposit->data->txs[0]->confirmations;
$recipientCheck = $checkdeposit->data->txs[0]->amounts_received[0]->recipient;
$amountCheck = $checkdeposit->data->txs[0]->amounts_received[0]->amount;
// verifica se o txid já existe no banco de dados
$queryTxid = "SELECT COUNT(txid) as SOMA FROM depositBtc WHERE txid='$txidCheck'";
$cTxid = mysqli_query($conn, $queryTxid) or die(mysqli_error());
$consultTxid = mysqli_fetch_assoc($cTxid);
$txidverific = $consultTxid['SOMA'];
//atualiza a balança do jogador
if ($txidverific == 0) {
$upbalance = $balance + $amountCheck;
$queryCredit = "UPDATE players SET balance = '$upbalance' WHERE nick = '$nick'";
$conectCredit = mysqli_query($conn, $queryCredit);
//cria um deposito no banco de dados
$today = date('Y-m-d H:i:s');
$queryDeposit = "INSERT INTO depositBtc (idDeposit, datetoday, txid, amount, status, nick, confirmations, recipient) VALUES ('','$today','$txidCheck','$amountCheck','confirmed','$nick','$confirmationsCheck','$recipientCheck')";
$conectDeposit = mysqli_query($conn, $queryDeposit);
//create notificationsModal
$queryNotifyDeposit = "INSERT INTO notify (id, nick, notify, datetoday) VALUES ('','$nick','Hello ".$nick."! Added ".$amountCheck." LCOIN in your balance.','$today')";
$conectNotifyDeposit = mysqli_query($conn, $queryNotifyDeposit);
} else {
echo "";
}
} else {
echo "";
}
} catch (Exception $e) {
echo "";
}
The old page looks for a specific array and performs the functions of updating the balance, history and sending notification.
I want to know how I can do to create a loop in the entire array and not in item [0].
{#272 ▼
+"status": "success"
+"data": {#274 ▼
+"network": "DOGETEST"
+"txs": array:26 [▼
0 => {#289 ▼
+"txid": "43183135ae536e339fc82eafed9cde68b6fb89e5475675cc9a62c6539ad41908"
+"from_green_address": true
+"time": 1522183284
+"confirmations": 4
+"amounts_received": array:1 [▼
0 => {#284 ▼
+"recipient": "2N6chEr7VY3qqysPCgftAQzBHj4msXWjEbc"
+"amount": "4.10000000"
}
]
+"senders": array:1 [▶]
+"confidence": 1.0
+"propagated_by_nodes": null
}
1 => {#288 ▶}
2 => {#283 ▶}
3 => {#287 ▶}
4 => {#291 ▶}
5 => {#293 ▶}
6 => {#295 ▶}
7 => {#297 ▶}
8 => {#299 ▶}
9 => {#301 ▶}
10 => {#303 ▶}
11 => {#305 ▶}
12 => {#307 ▶}
13 => {#309 ▶}
14 => {#311 ▶}
15 => {#313 ▶}
16 => {#315 ▶}
17 => {#317 ▶}
18 => {#319 ▶}
19 => {#321 ▶}
20 => {#323 ▶}
21 => {#325 ▶}
22 => {#327 ▶}
23 => {#329 ▶}
24 => {#331 ▶}
25 => {#333 ▶}
]
}
}
I started creating a function in the controller to replace the old page with a function. I started creating and I stopped here.
public function depositBTCCheck()
{
$apiKey = config('larablockio.apiKeyBTC');
$obj = new LaraBlockIo($apiKey);
$checkdeposit = $obj->getReceivedTransactions();
dd($checkdeposit);
//HERE ... I WANT TO KNOW HOW TO DO THE LOOP NO ARRAY $checkdeposit
foreach ($checkdeposit as &$value) {
if ($checkdeposit->status = 'success' && $checkdeposit->data->txs[0]->confirmations >= 2){
}
}
}
Please or to participate in this conversation.