Difference between get() and first() method in laravel

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

The Eloquent Dilemma: Understanding the Difference Between get() and first() in Laravel

Welcome to the world of Eloquent ORM! As you are starting your journey with Laravel, understanding how the underlying Query Builder methods behave is crucial. Many beginners, myself included at times, often get confused between methods like get() and first(). They both retrieve data from the database, but they serve fundamentally different purposes.

This post will break down exactly what each method does, when you should use them, and why this distinction matters for writing efficient Laravel code.


The Fundamentals: Querying Data in Eloquent

When you interact with the database through Eloquent (or the underlying Query Builder), you are essentially asking the database to return a set of results. The difference between get() and first() lies entirely in how that set of results is packaged and returned to your PHP application.

1. Using get(): Retrieving Collections

The get() method is designed to retrieve all matching records from the database query and return them as a Laravel Collection object.

When you use get(), the database executes the query, fetches every row that matches your where clauses, and bundles those results into a structured collection.

Code Example:

// Retrieve all flights where the 'active' status is 1
$flights = Flight::where('active', 1)->get();

// $flights will be an instance of Illuminate\Support\Collection
// It contains an array-like structure of Flight models.

When to use get():
Use get() when you expect to retrieve zero, one, or many records. This is the standard approach when you need to iterate over a list of items, display them in a table, or perform bulk operations on multiple records.

2. Using first(): Retrieving a Single Model

The first() method is specifically designed to retrieve only the first matching record from the result set and return it as an Eloquent Model instance.

If no records are found that match your criteria, first() will simply return null.

Code Example:

// Retrieve only the very first flight where the 'active' status is 1
$flight = Flight::where('active', 1)->first();

// $flight will be an instance of the Flight model, or null if no record exists.

When to use first():
Use first() when you are absolutely certain you only need one specific record. This is highly efficient because once the database finds the first match, it can stop searching immediately, which saves time and reduces the amount of data transferred over the network.


The Critical Distinction: Performance and Semantics

The core difference between these two methods boils down to what you expect to receive and how efficiently the query is executed.

Feature get() first()
Return Type Illuminate\Support\Collection (A collection of Models) Illuminate\Database\Eloquent\Model or null
Result Set All matching records. Only the first matching record found.
Use Case Retrieving lists, iterating over results. Retrieving a single entity by ID or a unique condition.
Performance Fetches and processes all results. Stops searching immediately upon finding the first result (more efficient for single lookups).

When you are dealing with database queries, especially when optimizing for performance—a key concept in building scalable applications like those promoted by Laravel—choosing the right method is vital. If you only need one item, using first() is semantically clearer and potentially faster because the database engine knows it doesn't need to process the entire result set.

Conclusion: Choosing the Right Tool

As a developer, your choice between get() and first() should be driven by your application's intent:

  1. Need a List? If you are building a dashboard or a list view, use get().
  2. Need a Single Item? If you are fetching a user profile by ID, checking for the existence of a specific setting, or retrieving the newest record, use first().

Mastering these small details helps you write cleaner, more readable, and ultimately, more performant Laravel code. Keep exploring the documentation—it’s the best resource for mastering Eloquent!