---
title: "eachSpread() and mapSpread() Methods in Laravel Collections"
url: "https://magecomp.com/blog/eachspread-mapspread-methods-laravel/"
date: "2026-09-12T08:02:38+00:00"
modified: "2026-09-12T08:02:40+00:00"
author:
  name: "Bharat Desai"
  url: "https://magecomp.com"
categories:
  - "Laravel"
word_count: 450
reading_time: "3 min read"
summary: "When working with collections in Laravel, we sometimes encounter items that contain multiple values. In such a case, Laravel offers us two methods: eachSpread() and mapSpread() to handle such value..."
description: "Learn how to use eachSpread() and mapSpread() Methods in Laravel Collections"
keywords: "Laravel"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Laravel 9: New Database Commands You Must Know"
    url: "https://magecomp.com/blog/laravel-9-new-database-commands/"
  - title: "How to Implement API Versioning in Laravel"
    url: "https://magecomp.com/blog/implement-api-versioning-laravel/"
  - title: "Laravel 10 Authentication using Jetstream"
    url: "https://magecomp.com/blog/laravel-10-authentication-using-jetstream/"
---

# eachSpread() and mapSpread() Methods in Laravel Collections

_Published: September 12, 2026_  
_Author: Bharat Desai_  

![eachSpread() and mapSpread() Methods in Laravel Collections](https://magecomp.com/blog/wp-content/uploads/2026/09/eachSpread-and-mapSpread-Methods-in-Laravel-Collections-1024x512.webp)

When working with collections in Laravel, we sometimes encounter items that contain multiple values. In such a case, Laravel offers us two methods: eachSpread() and mapSpread() to handle such values accordingly.

In this post, we will see the functionality of both methods using a use case example.

[![Laravel Development Services](https://magecomp.com/blog/wp-content/uploads/2024/12/Laravel-Development-Services-3-1024x284.webp)](https://magecomp.com/services/laravel-development-services/)

## Prerequisites
 1. Composer (Latest Version)

 2. Laravel 12

 3. Basic knowledge of Laravel Collections

## Steps
 1. Create a new Laravel project

 2. Create sample collection data

 3. Use eachSpread() method

 4. Use mapSpread() method

 5. Test the output

### Step 1: Create a New Laravel Project
Let’s start by creating a new Laravel project using Composer.

```
composer create-project laravel/laravel collection-method
```

Now, go inside the folder:

```
cd collection-method
```

### Step 2: Create Sample Collection Data
Now, open the routes/web.php file and edit it as below:

```
<?php
use IlluminateSupportFacadesRoute;
Route::get('/products', function () {
    $products = collect([
        ['Phone', 50000, 2],
        ['Shirt', 2000, 3],
        ['Pent', 1000, 5],
    ]);
    return response()->json($products);
});
```

Now, let’s use the eachSpread() method with this collection.

### Step 3: Use the eachSpread() Method
Edit the /products route as below:

```
use IlluminateSupportFacadesRoute;
Route::get('/products', function () {
    $products = collect([
        ['Phone', 50000, 2],
        ['Shirt', 2000, 3],
        ['Pent', 1000, 5],
    ]);
    $products->eachSpread(function ($name, $price, $quantity) {
        echo $name . ' - Price: ' . $price . ' - Quantity: ' . $quantity . '
';
    });
});
```

### Step 4: Use the mapSpread() Method
Now, let’s use the mapSpread() method.

Edit the /products route:

```
use IlluminateSupportFacadesRoute;
Route::get('/products', function () {
    $products = collect([
        ['Phone', 50000, 2],
        ['Shirt', 2000, 3],
        ['Pent', 1000, 5],
    ]);
    $totals = $products->mapSpread(function ($name, $price, $quantity) {
        return [
            'name' => $name,
            'total' => $price  $quantity,
        ];
    });
    return response()->json($totals);
});
```

### Step 5: Test the Output
Now, start the Laravel development server:

```
php artisan serve
```

Open the following URL in your browser:

http://127.0.0.1:8000/products

The output will be:

```
[
    {
        "name": "Phone",
        "total": 100000
    },
    {
        "name": "Shirt",
        "total": 6000
    },
    {
        "name": "Pent",
        "total": 5000
    }
]
```

## Conclusion
So, these methods are helps in Laravel collection methods when each collection item has multiple values, and we want to pass those values directly to the callback.

[![Hire Laravel Developer](https://magecomp.com/blog/wp-content/uploads/2024/12/Hire-Laravel-Expert-Now-2-1024x284.webp)](https://magecomp.com/services/hire-laravel-developer/)

## FAQ
**1. What is the eachSpread() method in Laravel Collections?**

The eachSpread () method in Laravel Collections refers to a situation where it is applied to collection elements and results in passing the inner values as distinct arguments to the callback.

**2. What is the mapSpread() method in Laravel Collections?**

The mapSpread function in Laravel Collections means that the callback is applied to elements, sending values inside of them as separate arguments.

**3. What is the difference between eachSpread() and mapSpread()?**

The key difference is that while the eachSpread method is used just to perform actions over the collection items without transforming their values, the mapSpread method helps to transform each item.


---

_View the original post at: [https://magecomp.com/blog/eachspread-mapspread-methods-laravel/](https://magecomp.com/blog/eachspread-mapspread-methods-laravel/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-12 08:51:03 UTC_  
