darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.33k stars 436 forks source link

Simple Instance #35

Closed hakimihamdan88 closed 8 years ago

hakimihamdan88 commented 8 years ago

Possible to have instance like this?

Cart::instance('shopping')->add(455, 'Sample Item', 100.99, 2, array());
SimoTod commented 8 years ago

I think you have to register a new service provider (https://github.com/darryldecode/laravelshoppingcart#instances) and get the instance from Laravel DI container (http://laravel.com/docs/5.1/container#resolving), This facade always return default instance named 'cart'. @darryldecode correct me if I'm wrong.

darryldecode commented 8 years ago

@SimoTod, yes you are right. When you add a new instance by following here (https://github.com/darryldecode/laravelshoppingcart#instances).. Eg. you added new "wishlist" instance of a cart.. you will need to this like so:

$WishlistCart = app('wishlist');

WishlistCart::add(455, 'Sample Item', 100.99, 2, array());

and so on..

hakimihamdan88 commented 8 years ago

@darryldecode possible without using service provider? exacty like https://github.com/Crinsane/LaravelShoppingcart#instances

mohamedsabil83 commented 5 years ago

It's better to save the instance name in DB and get it with ->instance('instance_name') rather than create a provider for each instance. Any plan to do that?