Okay after hours of research and still using DB::select I have to ask this question. Because I am about to trough my computer away ;).
I want to get the last input of a user (base on the timestamp). I can do this with the raw sql
SELECT c.*, p.*
FROM users c INNER JOIN
(
SELECT user_id,
MAX(created_at) MaxDate
FROM `catch-text`
GROUP BY user_id
) MaxDates ON c.id = MaxDates.user_id INNER JOIN
`catch-text` p ON MaxDates.user_id = p.user_id
AND MaxDates.MaxDate = p.created_at
I got this query from another post here on stackoverflow.
I have tried everything to do this with the fluent query builder in Laravel however with no success.
I know the manual says you can do this:
DB::table('users')
->join('contacts', function($join)
{
$join->on('users.id', '=', 'contacts.user_id')->orOn(...);
})
->get();
But that is not helping much because I do not see how I could use a subquery there?
Anyone who can light up my day?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…