@@ -35,13 +35,12 @@ public function __construct($instanceName, $storage)
35
35
$ this ->instanceName = $ instanceName ;
36
36
$ this ->storage = $ storage ;
37
37
$ this ->cart = $ this ->storage instanceof Model
38
- ? $ this ->storage ->all ()->where ("user_id " , \Auth::user ()->id )->mapWithKeys (function ($ item ) {
39
-
38
+ ? $ this ->storage ->all ()->where ('user_id ' , \Auth::user ()->id )->mapWithKeys (function ($ item ) {
40
39
return [$ item ['rowId ' ] => [
41
- 'id ' => $ item ['rowId ' ],
42
- 'price ' => $ item ['price ' ],
43
- 'quantity ' => $ item ['quantity ' ],
44
- 'cartable_id ' => $ item ['cartable_id ' ],
40
+ 'id ' => $ item ['rowId ' ],
41
+ 'price ' => $ item ['price ' ],
42
+ 'quantity ' => $ item ['quantity ' ],
43
+ 'cartable_id ' => $ item ['cartable_id ' ],
45
44
'cartable_type ' => $ item ['cartable_type ' ],
46
45
]];
47
46
})
@@ -125,7 +124,8 @@ public function has($key): bool
125
124
}
126
125
127
126
/**
128
- * check if exists session
127
+ * check if exists session.
128
+ *
129
129
* @return bool
130
130
*/
131
131
public function hasSession ()
@@ -136,7 +136,8 @@ public function hasSession()
136
136
}
137
137
138
138
/**
139
- * Move session to database
139
+ * Move session to database.
140
+ *
140
141
* @return $this
141
142
*/
142
143
public function moveSessionToDatabase ()
@@ -145,13 +146,13 @@ public function moveSessionToDatabase()
145
146
$ session = \Session::get ($ this ->instanceName );
146
147
\Session::forget ($ this ->instanceName );
147
148
$ session ->each (function ($ item ) {
148
- $ cart= $ this ->cart ->where (" cartable_id " , $ item [" cartable_id " ])->where (" cartable_type " , $ item [" cartable_type " ])->first ();
149
+ $ cart = $ this ->cart ->where (' cartable_id ' , $ item [' cartable_id ' ])->where (' cartable_type ' , $ item [' cartable_type ' ])->first ();
149
150
if (!is_null ($ cart )) {
150
- $ item [" id " ]= $ cart [" id " ];
151
- $ item [" quantity " ]+= $ cart [" quantity " ];
152
- $ item [" price " ]= $ cart [" price " ];
151
+ $ item [' id ' ] = $ cart [' id ' ];
152
+ $ item [' quantity ' ] += $ cart [' quantity ' ];
153
+ $ item [' price ' ] = $ cart [' price ' ];
153
154
}
154
- $ this ->cart ->put ($ item [" id " ], $ item );
155
+ $ this ->cart ->put ($ item [' id ' ], $ item );
155
156
});
156
157
$ this ->save ();
157
158
}
@@ -174,7 +175,7 @@ public function delete($key): CartService
174
175
}
175
176
$ this ->cart ->forget ($ item ['id ' ]);
176
177
if ($ this ->storage instanceof Model) {
177
- $ this ->storage ->where (" id " , \Auth::user ()->id )->firstWhere ('rowId ' , $ key )->delete ();
178
+ $ this ->storage ->where (' id ' , \Auth::user ()->id )->firstWhere ('rowId ' , $ key )->delete ();
178
179
} else {
179
180
$ this ->save ();
180
181
}
@@ -191,7 +192,7 @@ public function flush(): CartService
191
192
{
192
193
$ this ->cart = collect ([]);
193
194
if ($ this ->storage instanceof Model) {
194
- $ this ->storage ->where (" id " , \Auth::user ()->id )->delete ();
195
+ $ this ->storage ->where (' id ' , \Auth::user ()->id )->delete ();
195
196
} else {
196
197
$ this ->save ();
197
198
}
0 commit comments