I have a case where I need to maintain some values of a user locally while there are default values for each record. For example a user's default preference for theme is red but some users want blue theme or it can be more complicated a product can have some configuration like specifications and prices we can maintain a copy of product locally for the user where he can modify specification or price and does not affect the other users product. If a user haven't touched the product they can simple have default product values.
Is there any simple method in laravel to handle this situation. I tried searching forums but may be I am not getting the correct terms or the problem is not so common. Please help. Thanks.
This is a very broad question and would depend on the specifics.
For a product, the usual pattern is to retrieve a product with all its defaults from a database and then keep in memory (typically in a session). Only the copy in memory is changeable by the user, the db original is unaffected.
For a user preference, like theme, I would set your default application theme to red in the application itself, then check for any user preference for theme, if no preference, keep app default, otherwise use the preference indicated by the user.
@flarpy thanks for reply.
I have a price table which will be available to all the users but they can override the price according to their needs and this will just make a copy of record and next time user access the price which he modified it will return the modified price. While other prices will be default.
For now i am using below approach:
I just wanted to know is there a default laravel eloquent way or anything. As I need this same functionality on many type of records.
FYI - Default records are dynamic, CURD operations are performing on them as well.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community