hasMany(User::class, 'id', 'user_id'); } public static function session($sessionId) { $instance = new static(); // Create an instance of the class $instance->sessionUnique = $sessionId; // Set the session ID return $instance; // Return the instance for chaining } public function getCart() { return self::where('user_id', user()->id)->limit(5)->get(); } public function store($data) { // Add cart item to the database with the session ID from $this return self::insert(array_merge(['user_id' => user()->id], $data)); } public static function updateCart($uniqueId, $data) { // Update the cart item based on the unique ID and the session ID from $this return self::where('id', $uniqueId)->where('user_id', user()->id)->update($data); } public function remove($uniqueId) { // Remove the cart item based on the unique ID and the session ID from $this return self::where('id', $uniqueId)->where('user_id', $this->id)->delete(); } public function getTotal() { // Get the total cart amount based on the session ID from $this return self::where('user_id', $this->id)->sum('price'); } public function getSubTotal() { // Get the subtotal cart amount based on the session ID from $this return self::where('user_id', $this->id) ->selectRaw('SUM(price * quantity) as subtotal') ->value('subtotal'); } }