Laravel 7/6 Pluck Example | How to use pluck() in Laravel 6

Today, We want to share with you Laravel 7/6 Pluck Example | How to use pluck() in Laravel 6 | PHP.In this post we will show you laravel array to collection, hear for laravel add to collection we will give you demo and example for implement.In this post, we will learn about how can i use pluck() with chunk() laravel? with an example.

In this Article,We would All about the how you can use pluckchunk method in laravel version 7/6 and 5. I am display very easy example of pluckchunk query builder step by step demo in laravel version for 7/6 and 5. you can MySQL Database table to get array in values using PHP laravel pluckchunk method.

pluck in laravel | pluck laravel 6 | laravel pluck 7

pluckchunk in laravel
pluckchunk in laravel

it can get MySQL Database Table value column as well as key using pluckchunk method. Laravel pluckchunk method to returned Data collection single column or each a custom key column following simple Laravel example.

  Laravel Eloquent Collection Sort By Relation column

here the use pluckchunk in laravel example.

Example 1: laravel pluck single value

Now, simple example Database single column for the returned all the data Collection

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index(){
   
   $player_ids = \DB::table('players')->pluck('id');

   dd($player_ids);
}

Laravel Output Print
array:[
    0 => 008
    1 => 524
    2 => 145
   ]

Example 2:Laravel pluck() multiple attributes from Eloquent

here simple example each a custom Data key column for the returned all the data Collection.

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index(){
   
   $players  = Player::pluck('pname','id');

   dd($players);
}

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

Laravel Output Print

array:4 [
    1 => "Rahul"
    2 => "Sachin"
    3 => "virat"
  ]

Using Laravel Plucks To Extract Certain Values

$members = collect([
    ['name' => 'Kinjal Dave', 'email' => '[email protected]', 'city' => 'Ahemdabad'],
    ['name' => 'Jigar Lodnj', 'email' => '[email protected]', 'city' => 'Rajkot'],
    ['name' => 'Sangita Gondaliya', 'email' => '[email protected]', 'city' => 'Surat'],
    ['name' => 'Ayushui Patel', 'email' => '[email protected]', 'city' => 'Kalavad'],
    ['name' => 'Infinity Vaka Amita', 'email' => '[email protected]', 'city' => 'Jamanagar'],
]);

$members = $members->pluck('name')
// ['Kinjal Dave', 'Jigar Lodnj', 'Sangita Gondaliya', 'Ayushui Patel', 'Infinity Baka Amita'];

$members = Member::all();
$membernames = $members->pluck('membername');

$members = Member::all()->pluck('membername');

$members = Member::with('profile')->get();
$bio = $members->pluck('profile.bio'); // Get all bio of all members profile

Web Programming Tutorials Example with Demo

Read :

  Group By with Multiple Columns using Laravel Collection

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about collection laravel where nested only pluckchunk.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel Query Builder Join with subquery Example
  2.   Laravel Return Ajax JSON Response Example
  3.   Angular 6 - User Registration and Login Example & Tutorial
  4.   jquery image upload preview Delete option
  5.   Group By with Count using Laravel Collection
  6.   Sweet Alert confirmation before delete in Laravel 5.7
  7.   How to Merge Two Eloquent Collections in Laravel?
  8.   Add and Delete rows Dynamically using jQuery
  9.   Laravel Advance Database Query Builder
  10.   Menu Based Program in PHP Using Switch case

Leave a Reply

Your email address will not be published. Required fields are marked *