Articles tagged with laravel

Laravel’s Mysteriously Macroable Paginators

Laravel’s Macroable trait is a very neat way to add new functionality to built-in classes.

I recently found myself with the need to add a custom method to the LengthAwarePaginator class. Not a problem, I thought, I’ll write a quick macro.

A fine solution, but for the fact the LengthAwarePaginator isn’t “macroable”. Or so it would seem at first glance.

Eloquent Attributes and Database Defaults

There’s an important gotcha to remember when working with Eloquent and default database values: if you create a new model instance, without overriding a default value, the attribute will not be set.

There are three easy solutions to this problem. As you might expect, each comes with its own set of pros and cons.