I have following tables
Messages:
- user_id
- group_id
- text
- created_at
And
group_users:
- user_id
- left_at
- group_id
These tables have relationship via "group_id".
I need "Messages" that created before "group_user" left group.
In other word, i need a query like this:
$messages = Message::where('created_at','<',group_user.left_at)->get();
How can i achieve this?
2
Answers
it can be like the code below(untested):
in the Message model
in the controller
You can simply do it like this assuming you have the user ID at hand: