Seeking for experienced advice on structurizing the database table. I have a 7 day money balance table for each user, where the balances are calculated on-the-fly, but the incomings/outgoings are stored in the db.
Example:
https://pp.userapi.com/c855620/v855620022/868b5/mS5orfhQu84.jpg
How would you structure the database for this type of tabular data? Below I share three of my approaches.
https://pp.userapi.com/c855620/v855620022/868bc/4BZhoDSZ2FA.jpg
https://pp.userapi.com/c855620/v855620022/868c3/RXYebVZ3QTk.jpg
https://pp.userapi.com/c855620/v855620022/868d3/Si3Brz5Ul0k.jpg
Any best practices is very warmly welcomed and appreciated! Thanks!
Why not simply have two tables - your user and a simpler movements table
Movements would be something like:
user_id
movement_type (1, incoming, 2 outgoing)
movement_amount
movement_date
You can then do everything
maybe you need to have a 'transactions' table?
sample entry would be
id timestamp user_id incoming outgoing balance
1 2017-07-01 1 20 0 20
2 2017-07-02 1 0 100 120
and so on
so, you could access the 5th day transaction's balance for example as
$balance = $user->transactions()->get(4)->balance
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community