Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 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 5 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.

© 2024 Laravel.io - All rights reserved.