@@ -46,6 +46,7 @@ php artisan vendor:publish --provider="Darryldecode\Cart\CartServiceProvider" --
46
46
47
47
## HOW TO USE
48
48
49
+ - [ Quick Usage] ( #usage-usage-example )
49
50
- [ Usage] ( #usage )
50
51
- [ Conditions] ( #conditions )
51
52
- [ Items] ( #items )
@@ -58,6 +59,51 @@ php artisan vendor:publish --provider="Darryldecode\Cart\CartServiceProvider" --
58
59
- [ Using Different Storage] ( #storage )
59
60
- [ License] ( #license )
60
61
62
+ ## Quick Usage Example
63
+
64
+ ``` php
65
+ // Quick Usage with the Product Model Association & User session binding
66
+
67
+ $Product = Product::find($productId); // assuming you have a Product model with id, name, description & price
68
+ $rowId = 456; // generate a unique() row ID
69
+ $userID = 2; // the user ID to bind the cart contents
70
+
71
+ // add the product to cart
72
+ Cart::session($userID)->add(array(
73
+ 'id' => $rowId,
74
+ 'name' => $Product->name,
75
+ 'price' => $Product->price,
76
+ 'quantity' => 4,
77
+ 'attributes' => array(),
78
+ 'associatedModel' => $Product
79
+ ));
80
+
81
+ // update the item on cart
82
+ Cart::session($userID)->update($rowId,[
83
+ 'quantity' => 2,
84
+ 'price' => 98.67
85
+ ]);
86
+
87
+ // delete an item on cart
88
+ Cart::session($userID)->remove($rowId);
89
+
90
+ // view the cart items
91
+ $items = Cart::getContent();
92
+ foreach($items as $row) {
93
+
94
+ echo $row->id; // row ID
95
+ echo $row->name;
96
+ echo $row->qty;
97
+ echo $row->price;
98
+
99
+ echo $row->model->id; // whatever properties your model have
100
+ echo $row->model->name; // whatever properties your model have
101
+ echo $row->model->description; // whatever properties your model have
102
+ }
103
+
104
+ // FOR FULL USAGE, SEE BELOW..
105
+ ```
106
+
61
107
## Usage
62
108
63
109
### IMPORTANT NOTE!
@@ -127,7 +173,7 @@ Cart::add(455, 'Sample Item', 100.99, 2, array());
127
173
128
174
// array format
129
175
Cart::add(array(
130
- 'id' => 456,
176
+ 'id' => 456, // inique row ID
131
177
'name' => 'Sample Item',
132
178
'price' => 67.99,
133
179
'quantity' => 4,
@@ -157,7 +203,14 @@ Cart::add(array(
157
203
158
204
// add cart items to a specific user
159
205
$userId = auth()->user()->id; // or any string represents user identifier
160
- Cart::session($userId)->add(455, 'Sample Item', 100.99, 2, array());
206
+ Cart::session($userId)->add(array(
207
+ 'id' => 456, // inique row ID
208
+ 'name' => 'Sample Item',
209
+ 'price' => 67.99,
210
+ 'quantity' => 4,
211
+ 'attributes' => array(),
212
+ 'associatedModel' => $Product
213
+ ));
161
214
162
215
// NOTE:
163
216
// Please keep in mind that when adding an item on cart, the "id" should be unique as it serves as
0 commit comments