@@ -11,7 +11,7 @@ class LaravelCartDatabase implements Driver
1111 /**
1212 * Store item in cart.
1313 */
14- public function storeItem (Model |array $ item , ?int $ userId = null ): static
14+ public function storeItem (Model |array $ item , ?string $ userId = null ): static
1515 {
1616 $ cart = Cart::query ()->firstOrCreate (['user_id ' => $ this ->resolveUserId ($ userId )]);
1717 $ cart ->storeItem ($ item );
@@ -22,7 +22,7 @@ public function storeItem(Model|array $item, ?int $userId = null): static
2222 /**
2323 * Store multiple items in cart.
2424 */
25- public function storeItems (array $ items , ?int $ userId = null ): static
25+ public function storeItems (array $ items , ?string $ userId = null ): static
2626 {
2727 $ cart = Cart::query ()->firstOrCreate (['user_id ' => $ this ->resolveUserId ($ userId )]);
2828 $ cart ->storeItems ($ items );
@@ -33,7 +33,7 @@ public function storeItems(array $items, ?int $userId = null): static
3333 /**
3434 * Increase the quantity of the item.
3535 */
36- public function increaseQuantity (Model $ item , int $ quantity = 1 , ?int $ userId = null ): static
36+ public function increaseQuantity (Model $ item , int $ quantity = 1 , ?string $ userId = null ): static
3737 {
3838 $ cart = Cart::query ()->firstOrCreate (['user_id ' => $ this ->resolveUserId ($ userId )]);
3939 $ item = $ cart ->items ()->firstWhere ('itemable_id ' , $ item ->getKey ());
@@ -50,7 +50,7 @@ public function increaseQuantity(Model $item, int $quantity = 1, ?int $userId =
5050 /**
5151 * Decrease the quantity of the item.
5252 */
53- public function decreaseQuantity (Model $ item , int $ quantity = 1 , ?int $ userId = null ): static
53+ public function decreaseQuantity (Model $ item , int $ quantity = 1 , ?string $ userId = null ): static
5454 {
5555 $ cart = Cart::query ()->firstOrCreate (['user_id ' => $ this ->resolveUserId ($ userId )]);
5656 $ item = $ cart ->items ()->firstWhere ('itemable_id ' , $ item ->getKey ());
@@ -67,7 +67,7 @@ public function decreaseQuantity(Model $item, int $quantity = 1, ?int $userId =
6767 /**
6868 * Remove a single item from the cart
6969 */
70- public function removeItem (Model $ item , ?int $ userId = null ): static
70+ public function removeItem (Model $ item , ?string $ userId = null ): static
7171 {
7272 $ cart = Cart::query ()->firstOrCreate (['user_id ' => $ this ->resolveUserId ($ userId )]);
7373 $ itemToDelete = $ cart ->items ()->find ($ item ->getKey ());
@@ -79,7 +79,7 @@ public function removeItem(Model $item, ?int $userId = null): static
7979 /**
8080 * Remove every item from the cart
8181 */
82- public function emptyCart (?int $ userId = null ): static
82+ public function emptyCart (?string $ userId = null ): static
8383 {
8484 $ cart = Cart::query ()->firstOrCreate (['user_id ' => $ this ->resolveUserId ($ userId )]);
8585 $ cart ->emptyCart ();
@@ -90,7 +90,7 @@ public function emptyCart(?int $userId = null): static
9090 /**
9191 * Get option for item.
9292 */
93- public function getOption (string $ option , ?int $ itemId = null , ?int $ userId = null ): mixed
93+ public function getOption (string $ option , ?int $ itemId = null , ?string $ userId = null ): mixed
9494 {
9595 $ cart = Cart::query ()->firstOrCreate (['user_id ' => $ this ->resolveUserId ($ userId )]);
9696 $ items = $ cart ->items ()->when (! is_null ($ itemId ), function (Builder $ builder ) use ($ itemId ) {
@@ -103,7 +103,7 @@ public function getOption(string $option, ?int $itemId = null, ?int $userId = nu
103103 /**
104104 * Get all options of one item.
105105 */
106- public function getOptions (?int $ itemId = null , ?int $ userId = null ): mixed
106+ public function getOptions (?int $ itemId = null , ?string $ userId = null ): mixed
107107 {
108108 $ cart = Cart::query ()->firstOrCreate (['user_id ' => $ this ->resolveUserId ($ userId )]);
109109 $ items = $ cart ->items ()->when (! is_null ($ itemId ), function (Builder $ builder ) use ($ itemId ) {
@@ -116,7 +116,7 @@ public function getOptions(?int $itemId = null, ?int $userId = null): mixed
116116 /**
117117 * Set option for item.
118118 */
119- public function setOption (string $ key , mixed $ value , ?int $ itemId = null , ?int $ userId = null ): static
119+ public function setOption (string $ key , mixed $ value , ?int $ itemId = null , ?string $ userId = null ): static
120120 {
121121 $ cart = Cart::query ()->firstOrCreate (['user_id ' => $ this ->resolveUserId ($ userId )]);
122122 $ items = $ cart ->items ()->when (! is_null ($ itemId ), function (Builder $ builder ) use ($ itemId ) {
@@ -131,7 +131,7 @@ public function setOption(string $key, mixed $value, ?int $itemId = null, ?int $
131131 /**
132132 * Get option for item.
133133 */
134- public function addOption (string $ key , mixed $ value , ?int $ itemId = null , ?int $ userId = null ): static
134+ public function addOption (string $ key , mixed $ value , ?int $ itemId = null , ?string $ userId = null ): static
135135 {
136136 $ cart = Cart::query ()->firstOrCreate (['user_id ' => $ this ->resolveUserId ($ userId )]);
137137 $ items = $ cart ->items ()->when (! is_null ($ itemId ), function (Builder $ builder ) use ($ itemId ) {
@@ -146,7 +146,7 @@ public function addOption(string $key, mixed $value, ?int $itemId = null, ?int $
146146 /**
147147 * Resolve the user ID, defaulting to the authenticated user.
148148 */
149- protected function resolveUserId (?int $ userId ): int
149+ protected function resolveUserId (?string $ userId ): string
150150 {
151151 return $ userId ?? auth ()->id ();
152152 }
0 commit comments