1 year ago

Laravel query

Posted 1 year ago by Deekshith

Hi everyone, I have two tables namely, user and user_membership

users table has the following columns:


the user_membrship table has the following columns:


Now, users renew their membership every year. for example,

user table:

id name email mobile 1 Deekshith [email protected] 8908908908

and user_membership table have following entries,

user_membrship table:

id users_id started_date ended_date 1 1 2017-01-01 2017-12-31 1 1 2018-01-01 2018-12-31

now I want to expire all users which membership "ended_date" is lesser than the current date,

In above example user "deekshith" ended_date is expired so I want to get all expired users like the above user in table format. I have tried but I am getting only 2017-12-31 ended_date data instead of 2018-12-31 in the user_membership table.

My code is (Raw query),

SELECT users_membership.started_at,users_membership.ended_at,, FROM users_membership join users on users_membership.users_id = where users_membership.ended_at< '2019-01-25';

But it is displaying an only first entry of the user_membership table for a single user, but I want only last latest entry of the user_membership table for a particular user.

Please help me out.

Please sign in or create an account to participate in this conversation.