public function getListProductById($table, $idcate) { $Products = DB::table($table)->where("cate", "=", $idcate)->orderby('sort', 'asc')->get(); if ($Products) { return $Products; } return false; }
public function get_comments($id) { return DB::table('comments')->where('on_post', $id)->orderBy('id', 'desc')->get(); }
public static function moveNode($parent_id, $child_id, $position) { $sth = new static(); $new_parent = static::findOrFail($parent_id); $old_child[self::$atb[0]] = $child_id; $old_child = static::where(self::$atb[0], $old_child[self::$atb[0]])->first(); $space = $old_child[self::$atb[3]] - $old_child[self::$atb[2]] + 1; // Xác định left, right mới for ($i = $new_parent[self::$atb[2]] + 1;;) { if ($position == 1) { $new_child[self::$atb[2]] = $i; $new_child[self::$atb[3]] = $i + $space - 1; break; } else { $cur_child = static::where(self::$atb[2], $i)->first(); $i = $cur_child[self::$atb[3]] + 1; if ($old_child[self::$atb[2]] != $cur_child[self::$atb[2]]) { $position--; } } } //Update relevant nodes if ($new_child[self::$atb[2]] > $old_child[self::$atb[2]]) { $new_child[self::$atb[2]] -= $space; $new_child[self::$atb[3]] -= $space; $child_road = $new_child[self::$atb[2]] - $old_child[self::$atb[2]]; $space = -$space; $dau1 = '>'; $dau2 = '<='; $lr1 = self::$atb[2]; $lr2 = self::$atb[3]; } else { $child_road = $new_child[self::$atb[2]] - $old_child[self::$atb[2]]; $dau1 = '<'; $dau2 = '>='; $lr1 = self::$atb[3]; $lr2 = self::$atb[2]; } $little_child = DB::table(self::$tbl)->where(self::$atb[2], '>', $old_child[self::$atb[2]])->where(self::$atb[3], '<', $old_child[self::$atb[3]])->lists(self::$atb[0]); DB::table(self::$tbl)->whereIn(self::$atb[0], $little_child)->increment(self::$atb[2], $child_road); DB::table(self::$tbl)->whereIn(self::$atb[0], $little_child)->increment(self::$atb[3], $child_road); $need_update = DB::table(self::$tbl)->where($lr1, $dau1, $old_child[$lr1])->where($lr2, $dau2, $new_child[$lr2])->whereNotIn(self::$atb[0], $little_child)->lists(self::$atb[0]); DB::table(self::$tbl)->whereIn(self::$atb[0], $need_update)->increment(self::$atb[2], $space); DB::table(self::$tbl)->whereIn(self::$atb[0], $need_update)->increment(self::$atb[3], $space); DB::table(self::$tbl)->where($lr1, $dau2, $new_child[$lr2])->where($lr1, $dau1, $old_child[$lr1])->where($lr2, $dau1, $new_child[$lr2])->whereNotIn(self::$atb[0], $little_child)->whereNotIn(self::$atb[0], $need_update)->increment($lr1, $space); DB::table(self::$tbl)->where($lr2, $dau1, $old_child[$lr1])->where($lr2, $dau2, $new_child[$lr2])->where($lr1, $dau2, $old_child[$lr1])->whereNotIn(self::$atb[0], $little_child)->whereNotIn(self::$atb[0], $need_update)->increment($lr2, $space); static::where(self::$atb[0], $old_child[self::$atb[0]])->update($new_child); }
function getCategory() { return DB::table('product_type')->get(); }