Laravel 5.5 – Collection Dumping.

Posted by Rukmi Patel | September 20, 2017

Laravel 5.5 has introduced 2 new methods on collections class which makes debugging easier than before.

Lets take example of simple collection setup and pipe through some filters.

collect([1,2,3])->map(function($i){
     return $i * 2;
})->reject(function($i){
     return $i < 3;
});

One can now get to know what happens on each step of chain and has option to either “dump” or “dump-and-die” at any step of chain.

 
collect([1,2,3])->map(function($i){ 
    return $i * 2; 
})->dump()->reject(function($i){ 
    return $i < 3; }); 

dump() outputs the result and continue processing. Above code will result:

Collection {#181 ▼
    #items: array:3 [▼
       0 => 2
       1 => 4
       2 => 6
    ]
}

dd() will simple dump and stop execution from that point only.

collect([1,2,3])->map(function($i){
    return $i * 2;
})->dd()->reject(function($i){
    return $i < 3;
});

will result in to:

array:3 [▼
     0 => 2
     1 => 4
     2 => 6 
]
Blog Comments

Thanks for sharing these tips! I am sure your tips really helpful!

Add a comment

*Please complete all fields correctly

Related Blogs

Posted by Rukmi Patel | December 2, 2019
iTreeni Technolabs Outshines at GoodFirms by Providing End-To-End Business Solutions
Empowering clients' business by leveraging technology-enabled solutions endows iTreeni Technolabs to tap into the list of top web development companies in Australia at GoodFirms. View iTreeni Technolabs' GoodFirms' profile to...
MEAN-Vs-Full-stack
Posted by Rukmi Patel | April 9, 2019
Comparing Full Stack V/S MEAN Stack approach
The web and mobile app development services have stepped up to next level in last 5 years. Web and apps are all built utilizing a ‘stack’ of various technologies like...
Posted by Rukmi Patel | September 6, 2018
Headless Drupal or DeCoupled Drupal
Now a days, front-end technologies like Angular, React.js, Backbone.js etc have started attracting audience because of its advantages over traditional rendering approach. Server side frameworks like Laravel, Node.js have already...