Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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.

0

@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:

  1. Created 2 different tables one master and other local. Local keeps user modified values.
  2. When a user ask for prices I fetch record from both the tables and combine them by looping as there are 3-4 fields along with price. Create an array and return.

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.

0

FYI - Default records are dynamic, CURD operations are performing on them as well.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

asachanfbd asachanfbd Joined 27 May 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.