Laravel offers “when” method in its eloquent ORM which makes easier for developers to set conditionals in their queries. Similar to this, there is also “when” method in collection too.
For example: You may have written queries like:
In alternative way, using when method of collection, we are able to write like this.
It seems like alternative looks more to write. But wait,
Everything is awesome.