Example of refactoring a PHP loop with foreach-if-else structure into a one-liner using Laravel collections, including a unit test that ensure the refactored code still works.
Original tweet: https://twitter.com/PovilasKorop/status/1485239396257390595
More Collection Tips: https://github.com/LaravelDaily/laravel-tips/blob/master/Collections.md
– – – – –
Support the channel by checking out our products:
– Enroll in my Laravel courses: https://laraveldaily.teachable.com
– Try our Laravel QuickAdminPanel: https://bit.ly/quickadminpanel
– Buy my ready-made Laravel scripts: https://laraveldaily.gumroad.com
– Purchase my Livewire Kit: https://livewirekit.com
– Subscribe to my weekly newsletter: http://bit.ly/laravel-newsletter