Get ids in array from users table

Updated at 20-Aug-2021, By samar

Get ids in array from users table

With this article, we’ll look at some examples of how to address the "Get ids in array from users table" problem.

You can get the ids of the user's table in array form using the pluck() method. Sometimes we need ids in array form from table to perform some specific task in that case it will help you get the ids from the table.
  • Get array of ids from users table using pluck() method

    $userArrayIDs = User::get()->pluck('id');
    dd($userArrayIDs);
    
    Output :

    Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => 4 [1] => 41 [2] => 75 [3] => 77 [4] => 78 [5] => 79
    [6] => 80 [7] => 81 [8] => 82 [9] => 83 [10] => 84 ) )


    You can get all the ids of the user's table in an array form using the pluck() method in laravel.

Back to code snippet queries related laravel