Skip to content

Instantly share code, notes, and snippets.

@raank
Created July 6, 2016 23:40
Show Gist options
  • Save raank/39914e61cde48c74dc231631dac39e90 to your computer and use it in GitHub Desktop.
Save raank/39914e61cde48c74dc231631dac39e90 to your computer and use it in GitHub Desktop.
Função recursiva
<?php namespace App\Services;
use App\User;
class NetWorkService {
public function getUsers( $sponsor )
{
$users = User::where('sponsor', 'LIKE', '%' . $sponsor . '%')->get();
foreach($users->toArray() as $user) {
$network = (array) json_decode($user['sponsor']);
$list[] = [
'id' => $user['id'],
'login' => $user['name'],
'email' => $user['email'],
'name' => $user['nome'],
'network' => [
'nivel' => $network['nivel'],
'pos' => $network['pos']
],
'users' => $this->getUsers($user['name'])
];
}
return ($users ? $list : null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment