You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple shoppingcart implementation for Laravel 5, 6 and 7.
9
9
10
10
## Installation
11
11
12
-
Install the package through [Composer](http://getcomposer.org/).
12
+
Install the package through [Composer](http://getcomposer.org/).
13
13
14
14
Run the Composer require command from the Terminal:
15
15
16
-
composer require michaelbelgium/shoppingcart
17
-
16
+
composer require olimortimer/laravelshoppingcart
17
+
18
18
### Laravel <= 5.4
19
19
20
20
Should you still be on version 5.4 of Laravel, the final steps for you are to add the service provider of the package and alias the package. To do this open your `config/app.php` file.
@@ -71,8 +71,8 @@ Maybe you prefer to add the item using an array? As long as the array contains t
New in version 2 of the package is the possibility to work with the `Buyable` interface. The way this works is that you have a model implement the `Buyable` interface, which will make you implement a few methods so the package knows how to get the id, name and price from your model.
75
-
This way you can just pass the `add()` method a model and the quantity and it will automatically add it to the cart.
74
+
New in version 2 of the package is the possibility to work with the `Buyable` interface. The way this works is that you have a model implement the `Buyable` interface, which will make you implement a few methods so the package knows how to get the id, name and price from your model.
75
+
This way you can just pass the `add()` method a model and the quantity and it will automatically add it to the cart.
76
76
77
77
**As an added bonus it will automatically associate the model with the CartItem**
Because it can be very convenient to be able to directly access a model from a CartItem is it possible to associate a model with the items in the cart. Let's say you have a `Product` model in your application. With the `associate()` method, you can tell the cart that an item in the cart, is associated to the `Product` model.
317
+
Because it can be very convenient to be able to directly access a model from a CartItem is it possible to associate a model with the items in the cart. Let's say you have a `Product` model in your application. With the `associate()` method, you can tell the cart that an item in the cart, is associated to the `Product` model.
318
318
319
319
That way you can access your model right from the `CartItem`!
320
320
@@ -361,22 +361,22 @@ This will give you a `cart.php` config file in which you can make the changes.
361
361
To make your life easy, the package also includes a ready to use `migration` which you can publish by running:
This will place a `shoppingcart` table's migration file into `database/migrations` directory. Now all you have to do is run `php artisan migrate` to migrate your database.
366
366
367
-
### Storing the cart
367
+
### Storing the cart
368
368
To store your cart instance into the database, you have to call the `store($identifier) ` method. Where `$identifier` is a random key, for instance the id or username of the user.
369
369
370
370
Cart::store('username');
371
-
371
+
372
372
// To store a cart instance named 'wishlist'
373
373
Cart::instance('wishlist')->store('username');
374
374
375
375
### Restoring the cart
376
376
If you want to retrieve the cart from the database and restore it, all you have to do is call the `restore($identifier)` where `$identifier` is the key you specified for the `store` method.
0 commit comments