I am trying to get the last value of the login log of my user but I can't do it with this code:
DB::table('users')
    ->leftJoin('login_logs', 'login_logs.id', '=', function($query) {
        $query->select('login_logs.id')
            ->where('users.id', '=','login_logs.user_id')
            ->orderBy('login_logs.created_at')
            ->limit(1);
    })->get();
I got 2 tables users and login log I want to get all users with the last login log can someone give me a hand? I am new in Laravel.
Edit: i got this code for the sql:
SELECT c.*, o.* 
FROM users c 
INNER JOIN login_logs o ON o.id = (
SELECT id 
FROM login_logs 
WHERE login_logs.users_id = c.id 
ORDER BY id DESC 
LIMIT 1)
Edit2: this code work for me
DB::table('users')
->leftJoin('login_logs', 'login_logs.id', '=', (DB::RAW('(
SELECT id FROM login_logs 
WHERE login_logs.user_id = users.id 
ORDER BY login_logs.id DESC 
LIMIT 1)')))
->select('users.*','login_logs.created_at as lastLogin','login_logs.type')
->get()
some best ideas?:
 
     
     
    