I can query where relationships exist using the whereHas method, but now I need to get the opposite result, where the result does not match the result in the whereHas clause.
Here is my request:
$query->whereHas('actions', function ($query) {
$query->where('actions.created_at', '>', Carbon::now()->addDays(-30));
});
This gets things that have been in effect for the last 30 days, but I need to get something that has NOT been done in the last 30 days.
It seems I need to get max (actions.created_at) from the relationship and see if that value is> 30 days ago, but I'm not sure how I can do this with the eloquent one.
Note: the relationship between the person and the action is from 1 to many, so several action records can be connected, so I canβt just flip the statement as "<="
vonec source
share