How to log one to many activity? #792
Unanswered
airliajsmith
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hey, I would recommend a new column in the activity table like Activity::query()
->where(function (\Illuminate\Database\Eloquent\Builder $query) use ($customer) {
$query
->where(function (\Illuminate\Database\Eloquent\Builder $q) use ($customer) {
$q
->where('subject_type', $customer->getMorphClass())
->where('subject_id', $customer->getKey());
})
->orWhere(function (\Illuminate\Database\Eloquent\Builder $q) use ($customer) {
$q
->where('subject_type', (new Contact)->getMorphClass())
->whereIn('subject_id', $customer->contacts()->pluck('id'));
});
})
->latest()
->get(); This query should return all activities related to the customer or any of his contacts. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have many contacts for each customer, so I have a one to many table relationship. How do log the changes to the contact while linking them to the customer?
Right now I have to do this to get the activity of the customer:
How do I add the contacts to that?
Beta Was this translation helpful? Give feedback.
All reactions