Larakeep Package Brings Dedicated Keeper Classes for Laravel Model Field Computation
A new open-source Laravel package called Larakeep introduces a structured way to handle derived model fields such as computed totals, slugs, and cached counts. Developers install it via a single Composer command, after which a service provider auto-registers with no additional configuration needed. Each 'Keeper' is a plain PHP class containing formula methods for specific model columns, keeping computation logic separate from observers and model files. Models are linked to their Keeper classes using a HasKeepers trait and a KeptBy attribute, then fields are populated in memory by calling a process() method, which can be chained with save() to persist changes. The package also supports parameterized methods and custom verb prefixes, giving developers flexible control over when and how derived fields are calculated.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in