Support the ongoing development of Laravel.io →
Database Eloquent

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: This is what will be displayed to the user

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.

  1. One table for all information:

One table for all information

https://pp.userapi.com/c855620/v855620022/868bc/4BZhoDSZ2FA.jpg
  1. Separate tables for different movements: Separate tables for different movements:
https://pp.userapi.com/c855620/v855620022/868c3/RXYebVZ3QTk.jpg
  1. Two tables: one for days, one for movements: Two tables: one for days, one for movements
https://pp.userapi.com/c855620/v855620022/868d3/Si3Brz5Ul0k.jpg

Any best practices is very warmly welcomed and appreciated! Thanks!

Last updated 3 years ago.
0

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

0

maybe you need to have a 'transactions' table?

  1. id - the transaction id
  2. timestamp - when did this transaction occurred (im not sure why you are hardcoding days 1-7)
  3. user_id - to which user this transaction is for
  4. incoming - deposits/debits
  5. outgoing - withdrawal/credit
  6. balance - running balance

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
Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2025 Laravel.io - All rights reserved.