How to pluck multiple columns in Laravel

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

How to Pluck Multiple Columns in Laravel: A Developer's Guide

As developers working with relational databases through Laravel, a very common requirement arises: fetching more than one piece of data from a single record. For instance, when retrieving a student, we often need both their first_name and last_name. While the term "pluck" in Laravel is powerful for retrieving a single column, plucking multiple columns requires a slightly different, yet equally efficient, approach.

This post will dive into the most effective ways to retrieve multiple columns from your database using Laravel's Query Builder and Eloquent ORM, ensuring you write clean, maintainable, and performant code.

The Problem with Direct Plucking Multiple Fields

The concept of pluck() in Laravel is designed to extract a single value from a column across multiple rows (e.g., getting an array of all ids). Trying to use it directly for multiple columns often leads to confusion or incorrect results, as the method expects a single column name.

Your goal—getting first_name and last_name together—is better achieved by explicitly selecting those fields from the database layer first.

Method 1: Using the Query Builder with select() (The Direct SQL Approach)

When you are working directly with the Query Builder, the most explicit and powerful method is to use the select() method. This instructs the database exactly which columns you want returned, keeping your query highly optimized.

Here is how you would fetch both names for a student:

use Illuminate\Support\Facades\DB;

class StudentController extends Controller
{
    public function getStudentDetails($id)
    {
        $student = DB::table('students')
            ->where('id', $id)
            ->select('first_name', 'last_name') // Explicitly select the desired columns
            ->first();

        if (!$student) {
            return response()->json(['error' => 'Student not found'], 404);
        }

        // The result is an object/array containing both fields
        return response()->json([
            'first_name' => $student->first_name,
            'last_name' => $student->last_name,
        ]);
    }
}

Why this works: Using select('column1', 'column2') is the direct translation of a SQL SELECT first_name, last_name FROM students WHERE id = ?. This approach ensures you only pull the necessary data from the database, which is crucial for performance. For more complex interactions with Eloquent models, understanding these underlying database operations is key to mastering Laravel development, much like when exploring advanced features on laravelcompany.com.

Method 2: Using Eloquent Models (The Idiomatic Laravel Way)

If you are using Eloquent models (which is highly recommended in a full Laravel application), the process becomes even cleaner. Instead of manually selecting columns, you fetch the entire model and access its attributes.

Assuming you have an Eloquent model named Student:

use App\Models\Student;

class StudentController extends Controller
{
    public function getStudentFullName($id)
    {
        // Fetch the entire student record
        $student = Student::findOrFail($id); 

        // Accessing multiple columns directly from the model instance
        return response()->json([
            'full_name' => $student->first_name . ' ' . $student->last_name,
            'first_name' => $student->first_name,
            'last_name' => $student->last_name,
        ]);
    }
}

This method shifts the responsibility of column selection to the Eloquent model. If you need to retrieve these names frequently, defining accessors or mutators within your Student model can further streamline how data is presented to your application.

Method 3: Combining Columns in PHP (Post-Retrieval)

Sometimes, the most practical solution isn't just retrieving the raw columns, but combining them into a single, meaningful field for display. After retrieving the necessary data using either method above, you can easily concatenate the strings in PHP:

// Assuming $student is retrieved from Method 1 or 2
$fullName = $student->first_name . ' ' . $student->last_name;

Conclusion

To successfully pluck multiple columns in Laravel, avoid over-relying on a single method like pluck() for multi-column retrieval. Instead, embrace the power of explicit selection: use the Query Builder's select() method when interacting directly with the database, or leverage Eloquent models to fetch full records and access their attributes. By choosing the right tool—explicit SQL selection versus model hydration—you ensure your Laravel applications remain fast, readable, and robust.