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
Copy file name to clipboardexpand all lines: README.md
+20-19
Original file line number
Diff line number
Diff line change
@@ -12,21 +12,21 @@ A simple shoppingcart implementation for Laravel.
12
12
Install the package through [Composer](http://getcomposer.org/).
13
13
14
14
Run the Composer require command from the Terminal:
15
-
16
-
composer require hardevine/shoppingcart
17
-
15
+
```bash
16
+
composer require hardevine/shoppingcart
17
+
```
18
18
If you're using Laravel 5.5 or above, this is all there is to do.
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.
Now you're ready to start using the shoppingcart in your application.
31
31
32
32
**As of version 2 of this package it's possibly to use dependency injection to inject an instance of the Cart class into your controller or other class**
@@ -80,9 +80,9 @@ New in version 2 of the package is the possibility to work with the [Buyable](#b
80
80
This way you can just pass the `add()` method a model and the quantity and it will automatically add it to the cart.
81
81
82
82
The path to the `Buyable` interface is:
83
-
84
-
Gloudemans\Shoppingcart\Contracts\Buyable;
85
-
83
+
```php
84
+
Gloudemans\Shoppingcart\Contracts\Buyable;
85
+
```
86
86
**As an added bonus it will automatically associate the model with the CartItem**
87
87
88
88
```php
@@ -389,33 +389,34 @@ class Product exends Model implements Buyable {
389
389
To save cart into the database so you can retrieve it later, the package needs to know which database connection to use and what the name of the table is.
390
390
By default the package will use the default database connection and use a table named `shoppingcart`.
391
391
If you want to change these options, you'll have to publish the `config` file.
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.
402
402
403
403
### Storing the cart
404
404
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.
405
405
406
+
```php
406
407
Cart::store('username');
407
408
408
409
// To store a cart instance named 'wishlist'
409
410
Cart::instance('wishlist')->store('username');
410
-
411
+
```
411
412
### Restoring the cart
412
413
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.
413
-
414
+
```php
414
415
Cart::restore('username');
415
416
416
417
// To restore a cart instance named 'wishlist'
417
418
Cart::instance('wishlist')->restore('username');
418
-
419
+
```
419
420
## Exceptions
420
421
421
422
The Cart package will throw exceptions if something goes wrong. This way it's easier to debug your code using the Cart package or to handle the error based on the type of exceptions. The Cart packages can throw the following exceptions:
0 commit comments