Okay guys, i am trying to rephrase my question. Lets see how try 2 goes :)
I have a artisan command to calculate the total earnings for every user.
Every day a User gets earnings assigned. But sometime, how should I describe it, he made the earnings with stuff from another user.
And thats the assert_user_id column. If a user (user 2) made earnings with stuff from another user (user 1), these earnings should be added to the earnings of user 1 in this scenario.
id, user_id, earnings, asset_user_id
1, 1, 15, null
2, 1, 43, null
3, 1, 49, null
4, 2, 32, 1
5, 2, 25, 1
6, 2, 12, null
(In this case, user 2 is making almost all of his money with content from user 1... not very nice of him, thats why the money)
The Artisan commands gets all users. and goes through them with a foreach.
inside the foreach we call a method on the user model
return $this->sum('earnings');
remember, I am inside the collection of user 1.
And now I want to sum all earnings where asset_user_id = 1. The problem, the collection persist only the rows of user 1.
Now the question:
How can i access all other rows from inside a collection of a user. Yeha i could just do User:all() within my function in my model. But i don't think this would be SOLID code. So how do i do it the right way?