where('service_id', '=', $id)->delete(); } public function insertPricing(int $type, string $service_id, string $currency, float $price, int $term, float $as_usd, string $next_due_date, int $is_active = 1) { return self::create([ 'service_type' => $type, 'service_id' => $service_id, 'currency' => $currency, 'price' => $price, 'term' => $term, 'as_usd' => $as_usd, 'usd_per_month' => $this->costAsPerMonth($as_usd, $term), 'next_due_date' => $next_due_date, 'active' => ($is_active) ? 1 : 0 ]); } public function updatePricing(string $service_id, string $currency, float $price, int $term, float $as_usd, string $next_due_date, int $is_active = 1) { return DB::table('pricings') ->where('service_id', $service_id) ->update([ 'currency' => $currency, 'price' => $price, 'term' => $term, 'as_usd' => $as_usd, 'usd_per_month' => $this->costAsPerMonth($as_usd, $term), 'next_due_date' => $next_due_date, 'active' => ($is_active) ? 1 : 0 ]); } public static function allPricing() { return Cache::remember('all_pricing', now()->addWeek(1), function () { return DB::table('pricings') ->get(); }); } public static function pricingForService(string $service_id) { return Cache::remember("service_pricing.$service_id", now()->addWeek(1), function () use ($service_id) { return DB::table('servers as s') ->join('pricings as p', 's.id', '=', 'p.service_id') ->where('s.id', '=', $service_id) ->get(['s.*', 'p.*']); }); } }