Posted inTechnology / Laravel / php / Programming

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.

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);
}

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 :

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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype