Comments (6)
Hi,
Personally I bind the class as a singleton into Laravel 4's IoC container, so the same instance is used everywhere.
A better way I could do this is by creating a Facade, that way Laravel can automatically instantiate the class and provide a nice static API. So everywhere you see $cart->method()
you'll be able to use syntax like Cart::method()
I should be able to get a Facade in tonight. I'll keep this issue open for this feature.
from cart.
That would be the best! Thanks a ton for being so responsive! I'm going to be counting on this package for my future projects.
from cart.
Just created a new package moltin/laravel-cart
which provides a service provider and facade for Laravel 4.
To install this just replace moltin/cart
with moltin/laravel-cart
in your composer.json file. Then if your app/config/app.php
file add:
'Moltin\Cart\CartServiceProvider'
to your providers array and
'Cart' => 'Moltin\Cart\Facade'
to your aliases array. You'll then be able to access your cart from anywhere in your application by using Cart::method()
Hope this helps and if you have any issues then please let me know.
from cart.
The Facade seems to be working, except that the cart isn't being retained across requests.
A simple test like this:
Cart::insert(array(
'id' => 'foo',
'name' => 'bar',
'price' => 100,
'quantity' => 1,
'tax' => 20
));
foreach( Cart::contents(true) as $item ) :
print_r($item);
endforeach;
The Cart contents aren't being stored in Session or Locally ... is there some other configuration that needs to happen for the Cart to exists throughout the App?
from cart.
Try updating to the latest version. This issue should now be resolved.
from cart.
does anyone know how this would work for codeigniter?
from cart.
Related Issues (20)
- Adding multiple of the same item HOT 1
- Cart not available on new requests HOT 1
- Recalculate Tax after item as been added to the cart HOT 1
- Identifier HOT 4
- setIdentifier HOT 1
- Can't get item by its identifier
- Some way to change the session/storage identifier HOT 1
- Cart content storage after sesison HOT 2
- Add ability to add custom cart data HOT 1
- hasOptions
- Inserting over a product in the cart. HOT 1
- Qty and not showing more than 1 item in table
- Product ID with Different Size and Price value HOT 1
- Using remove(); HOT 28
- Stock and Add to Cart HOT 1
- Adding multiple items, saving to db HOT 4
- Issues installing via Composer HOT 1
- Cart::remove($remove_id) is not working.. HOT 1
- Example code HOT 2
- Payment method
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cart.