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.

Interviewed by Snipcart

Last week, Snipcart interviewed me as part of their Geek Talk series. In this wide-ranging exposé, we cover such thrilling topics as my favourite programmer and favourite quote, and we even find time to discuss some developer-type things.

The Hidden Perils of Craft Plugin Service Classes

When writing a Craft plugin, you should be very selective about what you put in your service classes.

This advice appears to run contrary to the guidance given in the official Craft documentation, and keeping your plugin code in service classes is certainly preferable to keeping it in your controller of variable classes. But it’s still a bad idea.

Here’s why.

Newer articles

Bend Craft to Your Will

Our newsletter helps you make the most of Craft. Join for free, leave any time.