public function test_query()
 {
     $items = Category::select('c.category_id', 'c.parent_id', 'cd.name', DB::raw('(SELECT count(category_id) FROM oc_category) AS childrenCount'))->from('oc_category as c')->where('c.parent_id', 0)->where('cd.language_id', 1)->join('oc_category_description as cd', 'c.category_id', '=', 'cd.category_id')->orderBy('c.sort_order')->get();
     $queries = DB::getQueryLog();
     $last_query = end($queries);
     var_dump($last_query['query']);
     var_dump(count($items));
     var_dump($items->count());
     $this->assertNotNull($items->count());
 }
 public function getParentsId($id)
 {
     /*
     $items = DB::select('SELECT t1.id AS level1,
                                      t2.id as level2,
                                      t3.id as level3,
                                      t4.id as level4,
                                      t5.id as level5,
                                      t6.id as level6,
                                      t7.id as level7,
                                      t8.id as level8,
                                      t9.id as level9,
                                      t10.id as level10
                           FROM categories AS t1
                                     LEFT JOIN categories AS t2 ON t2.parent_id = t1.id
                                     LEFT JOIN categories AS t3 ON t3.parent_id = t2.id
                                     LEFT JOIN categories AS t4 ON t4.parent_id = t3.id
                                     LEFT JOIN categories AS t5 ON t5.parent_id = t4.id
                                     LEFT JOIN categories AS t6 ON t6.parent_id = t5.id
                                     LEFT JOIN categories AS t7 ON t7.parent_id = t6.id
                                     LEFT JOIN categories AS t8 ON t8.parent_id = t7.id
                                     LEFT JOIN categories AS t9 ON t9.parent_id = t8.id
                                     LEFT JOIN categories AS t10 ON t10.parent_id = t9.id WHERE t1.id=?', [$id]);
     
     return $items;
     */
     $ids = [];
     $item = Category::find($id, ['id', 'parent_id']);
     while ($item != null) {
         $ids[] = $item->id;
         $item = Category::find($item->parent_id, ['id', 'parent_id']);
     }
     return array_reverse($ids);
 }