| Conditions | 3 |
| Paths | 3 |
| Total Lines | 13 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 46 | public static function getProducts($id = null){ |
||
| 47 | if($id === null){ |
||
| 48 | $products = Product::all(); |
||
| 49 | }else{ |
||
| 50 | if(Category::find($id)){ |
||
| 51 | $belong_to_this_category = Category::find($id)->children->pluck('id')->toArray(); |
||
|
|
|||
| 52 | $result = array_merge($belong_to_this_category, [0 =>$id]); |
||
| 53 | $products = Product::whereIn('category_id',$result)->get(); |
||
| 54 | }else{ |
||
| 55 | $products = []; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | return $products; |
||
| 59 | } |
||
| 61 |