DEV Community

Laravel Collections Higher Order Messages - Single Line Magic

Shobi on August 17, 2018

Collections are wrappers around arrays in PHP. Collections provide fluent interfaces and intuitive APIs to access arrays. Laravel comes with coll...
Collapse
 
govtvacancyjobs profile image
Government Jobs 2017

Great :)

Collapse
 
anwar_nairi profile image
Anwar

Very fluent!! Is this compatible with all Laravel versions?

Collapse
 
ppshobi profile image
Shobi

I think by Laravel, 5.4, this feature got introduced

Collapse
 
mattmangoni profile image
Matteo Mangoni

It's a nice feature, but it makes reading your code slightly harder.
It may seem like a good idea now, but your future self or your teammates may disagree.

Collapse
 
ppshobi profile image
Shobi

I should disagree with you here ;), as a developer when you write multiple nested ternary operators for a complex if conditional, I can understand that it reduces the readability, whereas when you write a ternary instead of a simple if condition in one line, rather I'd appreciate you,

Collapse
 
mattmangoni profile image
Matteo Mangoni

Maybe I just need to get used to it :)