Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel News:
Laravel Collection “tap” Method
Feb 20, 2017 @ 10:05:55

In this recent post to the Laravel News site Eric Barnes introduces a new method that's included in Laravel 5.4.10: the "tap" method.

Laravel 5.4.10 introduces a new tap method on collections which allow you to “tap” into the collection at a specific point and do something with the results while not affecting the main collection.

He includes an example, showing a sample array of user data and how, after converting it into a collection, he can "tap" into it at any point. He tapping pulls out the name of the current record following a "where" to locate the matching value. The quick post ends with a look at how the "tap" method is different from "pipe". Essentially the difference is that using "pipe" returns a different collection, potentially with modified data while "tap" does not.

tagged: laravel collection tap pipe method introduction

Link: https://laravel-news.com/collection-tap