Skip to content

Commit 4290204

Browse files
authored
Update README.md
1 parent df52560 commit 4290204

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

README.md

+20-19
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ A simple shoppingcart implementation for Laravel.
1212
Install the package through [Composer](http://getcomposer.org/).
1313

1414
Run the Composer require command from the Terminal:
15-
16-
composer require hardevine/shoppingcart
17-
15+
```bash
16+
composer require hardevine/shoppingcart
17+
```
1818
If you're using Laravel 5.5 or above, this is all there is to do.
1919

2020
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.
2121

2222
Add a new line to the `providers` array:
23-
24-
Gloudemans\Shoppingcart\ShoppingcartServiceProvider::class
25-
23+
```php
24+
Gloudemans\Shoppingcart\ShoppingcartServiceProvider::class
25+
```
2626
And optionally add a new line to the `aliases` array:
27-
28-
'Cart' => Gloudemans\Shoppingcart\Facades\Cart::class,
29-
27+
```php
28+
'Cart' => Gloudemans\Shoppingcart\Facades\Cart::class,
29+
```
3030
Now you're ready to start using the shoppingcart in your application.
3131

3232
**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
8080
This way you can just pass the `add()` method a model and the quantity and it will automatically add it to the cart.
8181

8282
The path to the `Buyable` interface is:
83-
84-
Gloudemans\Shoppingcart\Contracts\Buyable;
85-
83+
```php
84+
Gloudemans\Shoppingcart\Contracts\Buyable;
85+
```
8686
**As an added bonus it will automatically associate the model with the CartItem**
8787

8888
```php
@@ -389,33 +389,34 @@ class Product exends Model implements Buyable {
389389
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.
390390
By default the package will use the default database connection and use a table named `shoppingcart`.
391391
If you want to change these options, you'll have to publish the `config` file.
392-
392+
```bash
393393
php artisan vendor:publish --provider="Gloudemans\Shoppingcart\ShoppingcartServiceProvider" --tag="config"
394-
394+
```
395395
This will give you a `cart.php` config file in which you can make the changes.
396396

397397
To make your life easy, the package also includes a ready to use `migration` which you can publish by running:
398-
398+
```bash
399399
php artisan vendor:publish --provider="Gloudemans\Shoppingcart\ShoppingcartServiceProvider" --tag="migrations"
400-
400+
```
401401
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.
402402

403403
### Storing the cart
404404
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.
405405

406+
```php
406407
Cart::store('username');
407408

408409
// To store a cart instance named 'wishlist'
409410
Cart::instance('wishlist')->store('username');
410-
411+
```
411412
### Restoring the cart
412413
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
414415
Cart::restore('username');
415416

416417
// To restore a cart instance named 'wishlist'
417418
Cart::instance('wishlist')->restore('username');
418-
419+
```
419420
## Exceptions
420421

421422
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

Comments
 (0)