0

I am creating a cart on my website, everything is stored in session as serialized array.

I want to have helping functions like 'getPrize', 'getCart' and so on. Where should i store these functions?

example : 'getPrize' function will get the serialized array from session, foreach products and return final prize.

1 Answer 1

1

The simplest way is to use a simple shopping cart implementation like https://github.com/Crinsane/LaravelShoppingcart IMO. It already answers to all of your questions. If you don't want to use it, you can have a look at the source code, I think you will find some answers in it.

Now, about your question without using a lib, you can just build a Cart class extending Model (with all your method like getPrize and getCart), injecting Session in it, make a Service Provider for this class and then inject it in your controller.

Hope it will help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.