Learn how to get all IDs in an array using Laravel Pluck in just a few simple steps. This guide is perfect for beginners.
Here, i will give you two example of Laravel eloquent get all ids in array using collection pluck().
So, let's see bellow example:
Example 1:
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(){
$ids = Users::pluck('id');
dd($ids);
}
Output:
array:[
0 => 1
1 => 2
2 => 3
]
Example 2:
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(){
$names = Users::pluck('name', 'id');
dd($names);
}
Output:
array:4 [
1 => "Hardik"
2 => "Paresh"
3 => "Rajesh"
]
I hope it can help you.
#laravel