Laravel pluck method example | Laravel Pluck

  • 18-04-2022
  • 1176
  • Laravel 7
  • Haresh Chauhan

Hello, Developer

Here you see that how to Pluck data from Database in laravel by pluck method this is one of the simplest method to get specific column data trough to specify the name of the column it is very simple to learn as well as find out data from database using pluck method.

Whene you using pluck method at that time put that name which you want to get column it will show output array and whenever you put the name of the column and id in pluck method you will get the name of the column with id and that id become key of that name of a column, here webappfix below give an explanation with example do according to below example and you will get output from laravel pluck method.

Pluck method is a part of laravel it will retrieving a list of data from database in specify list and value given $array.

It is mostly using while compair in_array() two array and want's to unique result that time mostly used.

So, Here I will guide you step by step how to use Pluck method in laravel.

Example 1 : Controller

App/http/controller/dashboardController

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use User;

class dashboardController extends Controller
{
    $data = User::pluck('id','email');
    dd($data);
}

Output

array = [
        1 => abc@gmail.com,
        2 => xyz@gmail.com,
        3 => qwe@gmail.com
];

Without pluck id it will generate auto key.

jQuery load more data on scroll

Example 2 : Controller

App/http/controller/dashboardController

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use User;

class dashboardController extends Controller
{
    $data = User::pluck('email');
    dd($data);
}

array = [
        0 => abc@gmail.com,
        1 => xyz@gmail.com,
        2 => qwe@gmail.com
];

We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :