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.

How and When to Use PSR-4 Autoloading in Your Craft Plugins

If you’re developing a reasonably sophisticated Craft plugin, chances are you’ll have a lot of class files which don’t really fit into the “standard” Craft plugin sub-directories of models, records, and so forth.

In this situation, you need a way to easily loading your “non-standard” classes as-and-when they’re required. PSR-4 autoloading is the perfect solution to this problem, and by the end of this article you’ll know everything you need in order to use it in your plugins.

Newer articles

Bend Craft to Your Will

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