Code Monkey home page Code Monkey logo

Comments (6)

chrisnharvey avatar chrisnharvey commented on August 28, 2024

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.

dcolumbus avatar dcolumbus commented on August 28, 2024

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.

chrisnharvey avatar chrisnharvey commented on August 28, 2024

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.

dcolumbus avatar dcolumbus commented on August 28, 2024

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.

chrisnharvey avatar chrisnharvey commented on August 28, 2024

Try updating to the latest version. This issue should now be resolved.

from cart.

ableade avatar ableade commented on August 28, 2024

does anyone know how this would work for codeigniter?

from cart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.