/**
* parentsTree
* Retrieve all the categories parents of one passed through parameter,
* checking data from bottom to top
* @param [int] $id is the id category evaluated
* @param [array] $array is the array to be used out of the model
* @param [array] $fields is the array that contais the table field we want to retrieve
*/
public static function parentsTree($id, &$array, $fields = ['id', 'category_id', 'name'])
{
$categories = Category::select($fields)->where('id', $id)->get()->toArray();
if (is_null($categories)) {
return;
}
foreach ($categories as $value) {
$array[] = $value;
Category::parentsTree($value['category_id'], $array, $fields);
}
return;
}