Articles

Laravel 5 Collections: Converting a Collection Into Something JSON Serializable With jsonSerialize

Laravel 5 The jsonSerialize method will convert the contents of the collection into something that be serialized using PHP's json_encode function. This method will iterate the collection's internal array and will...

Laravel 5 Collections: Converting a Collection to JSON With PHP's Magic __toString Method

Laravel 5 When a Collection instance is cast into a string, its JSON representation is returned as the result. Internally this is accomplished by returning the results of the collection's toJson method. use...

Laravel 5 Collections: Converting a Collection's Contents to JSON With toJson

Laravel 5 The toJson method will return a JSON encoded version of the data stored within the collection instance. It internally does this by returning a call to PHP's json_encode function, passing in any $options that...

Laravel 5 Collections: Converting a Multi-Dimensional Collection Into a Single Dimension With collapse

Laravel 5 The collapse method combines all the first-level items of a collection into a new, single collection. The returned value of the collapse method is an instance of the Collection class. Signature public function...

Laravel 5 Collections: Creating a Copy of a Collection With toBase

Laravel 5 The toBase method will return a new collection instance containing all of the data in the current collection instance. This can be useful for method chaining when you need to modify the collection's contents...