Press "Enter" to skip to content

Laravel Macro does rescue always.

Sharing is caring!

Laravel has always been amazing to me on how much we can make stuffs for ourselves. Not just coding, but implementing functions that are useful to application too.

Macro is the one the best feature, developer adore in this framework.

Imagine you retrieve data from eloquent model like Model::all(). Here, You did not retrieve a single instance, you retrieved collection.

So, now you need to do something with it.

Let’s say you are looping over and printing values over tr and td combination in a table.

You will hate it when you have to do this every time.

So, to use macro here would be useful.

Next time

is enough.

Better yet those “id” and “name” can also be passed as function arguments. But, we can do optimization as we like.


Everything is awesome.


Be First to Comment

    Leave a Reply

    Your email address will not be published.