0

`

return $all_user = DB::select("SELECT *,
        'STATUS' AS STAT,
        CASE
             WHEN TIMESTAMPDIFF(MINUTE, updated_at, NOW()) <= 1 THEN 'online'
             WHEN (TIMESTAMPDIFF(MINUTE, updated_at, NOW()) > 720
               AND TIMESTAMPDIFF(MINUTE, updated_at, NOW()) <= 30) THEN 'idle'
             ELSE 'offline'
        END AS user_status
     FROM users")->paginate(20);

`

I'm expecting the result with paginate link. when i put ->paginate(20) it giving me Call to a member function paginate() on array error. please help

2
  • 1
    DB::select() executes the query immediately and returns an Array; []->paginate() is not valid. Use DB::table('users')->select('...')->paginate(10) as the answer below suggests, or use a Model (User::selectRaw('...')->paginate(10)) Commented Nov 9, 2022 at 15:45
  • @TimLewis Thanks the Eloquent Model User::selectRaw('...')->paginate(10) is working for me 😊. Commented Nov 9, 2022 at 16:39

1 Answer 1

2

maybe you can use:

return $all_user = DB::table('users')
   ->select(" *,
        'STATUS' AS STAT,
        CASE
             WHEN TIMESTAMPDIFF(MINUTE, updated_at, NOW()) <= 1 THEN 'online'
             WHEN (TIMESTAMPDIFF(MINUTE, updated_at, NOW()) > 720
               AND TIMESTAMPDIFF(MINUTE, updated_at, NOW()) <= 30) THEN 'idle'
             ELSE 'offline'
        END AS user_status
     FROM users")->paginate(20);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.