laravel v6x addselect always returns a null value for the subquery field

I might be wrong here but I think you have to use whereColumn instead of where to actually use the value of the column and not just a string with the column’s name.

$users = User::query()
    ->addSelect([
        'latest_login' => Login::select('login_time')
            ->whereColumn('logins.user_id', 'users.id')
            ->latest('login_time')
            ->take(1)
    ])
    ->orderBy('latest_login', 'DESC')
    ->get();

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top