mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-24 07:55:35 +00:00
Change wording of store/restore documentation a bit
This commit is contained in:
29
README.md
29
README.md
@@ -323,34 +323,41 @@ foreach(Cart::content() as $row) {
|
|||||||
echo 'You have ' . $row->qty . ' items of ' . $row->model->name . ' with description: "' . $row->model->description . '" in your cart.';
|
echo 'You have ' . $row->qty . ' items of ' . $row->model->name . ' with description: "' . $row->model->description . '" in your cart.';
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
# Database
|
## Database
|
||||||
|
|
||||||
- [Config](#configuration)
|
- [Config](#configuration)
|
||||||
- [Save Cart](#save-cart-to-database)
|
- [Storing the cart](#save-cart-to-database)
|
||||||
- [Retrieve Cart](#retrieve-cart-from-database)
|
- [Restoring the cart](#retrieve-cart-from-database)
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
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.
|
||||||
|
By default the package will use the default database connection and use a table named `shoppingcart`.
|
||||||
|
If you want to change these options, you'll have to publish the `config` file.
|
||||||
|
|
||||||
To save cart into database, you have to publish `migration` and `config` file.
|
php artisan vendor:publish --provider="Gloudemans\Shoppingcart\ShoppingcartServiceProvider" --tag="config"
|
||||||
|
|
||||||
php artisan vendor:publish --provider="Gloudemans\Shoppingcart\ShoppingcartServiceProvider"
|
This will give you a `cart.php` config file in which you can make the changes.
|
||||||
|
|
||||||
This will place a `shoppingcart` table's migration file into `database/migrations` directory and `cart` config file in `config` directory.
|
To make your life easy, the package also includes a ready to use `migration` which you can publish by running:
|
||||||
|
|
||||||
php artisan migrate
|
php artisan vendor:publish --provider="Gloudemans\Shoppingcart\ShoppingcartServiceProvider" --tag="migrations"
|
||||||
|
|
||||||
### Save cart to database
|
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.
|
||||||
To store your cart item into database you have to call `store($identifier) ` method.
|
|
||||||
|
### Storing the cart
|
||||||
|
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.
|
||||||
|
|
||||||
Cart::store('username');
|
Cart::store('username');
|
||||||
|
|
||||||
// To store a cart instance named 'wishlist'
|
// To store a cart instance named 'wishlist'
|
||||||
Cart::instance('wishlist')->store('username');
|
Cart::instance('wishlist')->store('username');
|
||||||
|
|
||||||
### Retrieve cart From database
|
### Restoring the cart
|
||||||
|
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.
|
||||||
|
|
||||||
Cart::restore('username');
|
Cart::restore('username');
|
||||||
|
|
||||||
// To restore a cart with instance name 'wishlist'
|
// To restore a cart instance named 'wishlist'
|
||||||
Cart::instance('wishlist')->restore('username');
|
Cart::instance('wishlist')->restore('username');
|
||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|||||||
Reference in New Issue
Block a user