I have two tables: users and user_actions. I need to get all users where('available', true) (...and some other logic) and order them by sum of user_actions.clicks column.
public function actions()
{
return $this->hasMany(UserActions::class);
}
I need something like this:
User::where('available', true)->where("something else....")->orderBy('sum(user_actions.clicks)', 'desc')->get();
The result must be a Collection of User class.