Laravel - When to use ->get()

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Laravel - When to use `->get()`: Unpacking the Collection Power I'm confused as to when `->get()` in Laravel is actually required. It seems redundant when I'm just fetching a single record using methods like `find()`, or when I’m executing raw database queries directly via the Query Builder, such as `DB::table('users')->find(1)`. The official documentation mentions using `get()` or `first()`, but the distinction between retrieving a single item and retrieving an entire set of results is often lost in the noise of Eloquent and the Fluent Query Builder. This post will dive deep into the specific scenarios where using `->get()` is not just optional, but absolutely necessary, giving you a clear, developer-focused understanding of Laravel's data retrieval mechanisms. --- ## The Fundamental Difference: Single Item vs. Collection The core reason for this confusion lies in what each method returns: a single model instance versus a collection (an array-like structure) of models. ### Retrieving a Single Record (`find()` and `first()`) When you use methods like `User::find(1)` or `User::first(1)`, the goal is clearly to retrieve *one specific entity*. These methods are designed for efficiency; they execute the query and immediately hydrate the result into a single Model object (or `null` if not found). You don't need an extra layer of collection wrapping when you only expect one item. **Example:** ```php $user = User::find(1); // Returns a single User Model object // $user is an instance of the User class, not a collection. ``` ### Retrieving Multiple Records (`get()`) The `->get()` method, whether called on an Eloquent model or a Query Builder instance, is specifically designed to execute the query and return the results as a **Laravel Collection**. This is crucial when you anticipate receiving zero, one, or many rows back from your database operation. **Example:** ```php $users = User::get(); // Returns a Laravel Collection object containing all matching User Models // $users is an instance of Illuminate\Support\Collection. ``` ## When You Absolutely Need `->get()` The requirement for `->get()` emerges when your subsequent logic requires iteration, manipulation, or bulk operations on the retrieved data. If you only need a single item, using `find()` or `first()` is more direct and often slightly more performant because it stops processing as soon as the first result is found. ### 1. Iteration and Looping If you intend to loop through the results, you must use a collection object. Collections provide powerful, expressive methods for iteration (`foreach`, `map`, `filter`) that are far superior to iterating over raw arrays or single objects. ```php // Using get() allows easy iteration $allPosts = Post::where('status', 'published')->get(); foreach ($allPosts as $post) { // Perform complex logic on every post in the collection echo $post->title . "\n"; } ``` ### 2. Bulk Operations and Filtering When performing operations that affect multiple records simultaneously—such as updating, deleting, or sending mass emails—you typically operate on a collection retrieved via `get()`. This ensures you are working with the full set of results from the database query. For complex data retrieval patterns, understanding how to handle collections is fundamental. As detailed in the official documentation, mastering these methods allows you to leverage Laravel's built-in structure effectively. For more advanced Eloquent querying techniques, exploring resources like those found on [laravelcompany.com](https://laravelcompany.com) will provide deeper insights into optimizing your data interactions. ## Summary and Best Practices | Scenario | Recommended Method | Return Type | Rationale | | :--- | :--- | :--- | :--- | | **Finding one specific record** | `->find(id)` or `->first()` | Eloquent Model Object | Most direct, efficient for singular lookups. | | **Finding multiple records** | `->get()` | Laravel Collection | Necessary for iteration, mapping, and bulk operations. | | **Executing raw queries (DB facade)** | `DB::table('...')->get()` | Laravel Collection | Standard practice when using the Query Builder to fetch results. | In conclusion, you don't *always* need `->get()`, but you *must* use it whenever your subsequent code intends to process multiple database records. Think of `find()` and `first()` as tools for pinpoint retrieval, while `get()` is the tool for comprehensive data harvesting. Mastering this distinction will make your Laravel applications cleaner, more readable, and significantly more efficient.