• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Return new collection without modifying original collection

phplaravel-5collectionseloquent


PHP Snippet 1:

$original = collect([1, 2, 3, 4, 5]);

$modified = $original->map(function ($el) {
     return $el * 2; 
});

dd($modified);

PHP Snippet 2:

=> Illuminate\Support\Collection {#3726
     all: [
       2,
       4,
       6,
       8,
       10,
     ],
   }

PHP Snippet 3:

dd($original);

PHP Snippet 4:

=> Illuminate\Support\Collection {#3743
     all: [
       1,
       2,
       3,
       4,
       5,
     ],
   }

Related Snippets

Laravel 8 Multiple Relationships for Factory

send email using gmail-api and google-api-php-client

Add a text next to stock quantity if it is less than 10 in Woocommerce single product

Laravel database insert with combining array and string

How to create custom authentication in laravel 8?

Sync Records With Default Values in Pivot Tables, Call to undefined method syncWithPivotDefaults()

auth pages not getting css in laravel

Laravel Blade checkbox not checked

Display a product custom field only in WooCommerce Admin single orders

What is my SQL missing?

Send Outlook 2010 email using PHP

Laravel get rows with created_at not older than 24 hours

How to make a array inside array?

str_replace or preg_replace random number from string

Add Metadata, headers (Expires, CacheControl) to a file uploaded to Amazon S3 using the Laravel 5.0 Storage facade

About Contact Privacy policy Terms and conditions