PHPackages                             edulazaro/larakeep - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. edulazaro/larakeep

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

edulazaro/larakeep
==================

Maintenance Tasks for Laravel Models Fields

2.0.5(1mo ago)0573↓75.6%MITPHPPHP ^8.2

Since Oct 7Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/edulazaro/larakeep)[ Packagist](https://packagist.org/packages/edulazaro/larakeep)[ RSS](/packages/edulazaro-larakeep/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (6)Dependencies (4)Versions (8)Used By (0)

[![Larakeep](art/banner.png)](art/banner.png)

Keepers for Laravel
===================

[](#keepers-for-laravel)

 [![Total Downloads](https://camo.githubusercontent.com/aa8bd82151a875f1430dd08e5a390fd792e5c3e05f825f8362fbfab7c62c3598/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6564756c617a61726f2f6c6172616b656570)](https://packagist.org/packages/edulazaro/larakeep) [![Latest Stable Version](https://camo.githubusercontent.com/300192bed39bfb72afad6ffeca5ba418ddec53ff4e4885cabc33d6a16374479f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6564756c617a61726f2f6c6172616b656570)](https://packagist.org/packages/edulazaro/larakeep)

Introduction
------------

[](#introduction)

Larakeep is a package which allows to create and handle Keepers. Keepers allow to process the value of the desired model fields.

Sometimes, a field value must be configured when creating or updating a model instance. A common place to do this are the observers. This can lead to bloat the observers with repeated code or bloating the the models with functions, resulting in big files.

keepers allow to set the value of the desired fields on separate classes, keeping the code cleaner.

Actions VS Keepers
------------------

[](#actions-vs-keepers)

While Keepers and Actions share similarities, they serve different purposes in Laravel applications:

FeatureActions PatternKeepers (Larakeep)**Purpose**Perform a self-contained operation (e.g., `CreateUserAction`, `DeletePostAction`)Maintain or compute model field values dynamically**Scope**Often used for operations that affect multiple models or require business logicSpecific to maintaining values inside a model**Implementation**Typically standalone classes invoked as `SomeAction::run($params)`Assigned to models using attributes or manually (`keep()`)**Examples**`CreateInvoiceAction`, `SendNotificationAction``getFormattedName()`, `computeRankings()`- **Use Keepers when:** You need to centralize computed fields, enforce model-based transformations, or derive values dynamically.
- **Use Actions when:** You are performing operations that modify multiple models, involve services, or handle workflow logic.

How to install Larakeep
-----------------------

[](#how-to-install-larakeep)

Execute this command on the Laravel root project folder:

```
composer require edulazaro/larakeep
```

How to create a Keeper
----------------------

[](#how-to-create-a-keeper)

You can create a Keeper manually or using the `make` command:

```
php artisan make:keeper MyModelKeeper
```

The Keeper will be created by default for the model `\App\Models\MyModel`.

You can also specify the model you are creating the Keeper for by using a second argument:

```
php artisan make:keeper MyClassKeeper  "\App\Models\Whatever\MyModel"
```

In this case, the keeper will be created for the model `\App\Models\Whatever\MyModel`.

How to configure a Keeper
-------------------------

[](#how-to-configure-a-keeper)

After creating a Keeper, you will need to add the `HasKeepers` concern to the referenced model:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use EduLazaro\Larakeep\Concerns\HasKeepers;

class MyModel extends Model
{
    use HasKeepers;
}
```

### Registering Keepers manually

[](#registering-keepers-manually)

You can manually assign a Keeper to a model in a service provider's boot method:

```
namespace App\Providers;

use App\Models\MyModel;
use App\Keepers\MyModelKeeper;

class AppServiceProvider extends Model
{
    // ...
    public function boot()
    {
        // ...
        MyModel::keep(MyModelKeeper::class);
    }
}
```

You can add many Keepers to a single model:

```
MyModel::keep(MyModelKeeperA::class);
MyModel::keep(MyModelKeeperB::class);
```

### Registering Keepers using Attributes

[](#registering-keepers-using-attributes)

Alternatively, you can register Keepers using attributes directly in the model:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use EduLazaro\Larakeep\Concerns\HasKeepers;
use EduLazaro\Larakeep\Attributes\KeptBy;
use App\Keepers\MyModelKeeper;

#[KeptBy(MyModelKeeper::class)]
class MyModel extends Model
{
    use HasKeepers;
}
```

This method allows you to keep the registration clean and self-contained within the model itself, without needing to modify the service provider.

Larakeep supports assigning multiple Keepers to a model using multiple `#[KeptBy]` attributes:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use EduLazaro\Larakeep\Concerns\HasKeepers;
use EduLazaro\Larakeep\Attributes\KeptBy;
use App\Keepers\MyModelKeeperA;
use App\Keepers\MyModelKeeperB;

#[KeptBy(MyModelKeeperA::class)]
#[KeptBy(MyModelKeeperB::class)]
class MyModel extends Model
{
    use HasKeepers;
}
```

How to use a Keeper
-------------------

[](#how-to-use-a-keeper)

To use Keeper you need to use the word `get` + the camel case version of the model attribute to process. For example, it's common to keep separate the model name and the search string for the model. In this case a keeper method is handy to set the attribute value:

```
namespace App\Keepers;

use \App\Models\MyClass;

class MyClassKeeper
{
    // ...
    public function getSearchText()
    {
        return $this->myClass->name . ' ' . $this->myClass->tag;
    }
}
```

The method can also accept parameters, adding the keyword `With` to the method name:

```
namespace App\Keepers;

use \App\Models\MyClass;

class MyClassKeeper
{
    // ...
    public function getSearchTextWith($whatever)
    {
        return $this->myClass->name . ' ' . $this->myClass->tag;
    }
}
```

Now, on an observer, you can process the `search_text` field to set its value:

```
$myClassInstance->process('search_text'); // To execute the getSearchText method.
```

Or if the method has parameters:

```
$myClassInstance->processWith('search_text', 'Any string'); // To execute the getSearchTextWith method.
```

You can also pass an array of fields to process all of them at the same time:

```
$myClassInstance->process(['search_text', 'word_count']);
```

***The model will still need to be saved.***

How to add Tasks
----------------

[](#how-to-add-tasks)

You can prepend any other word than`get` to the keeper methods, like `configure`:

```
namespace App\Keepers;

use \App\Models\MyClass;

class MyClassKeeper
{
    // ...
    public function configureSearchText()
    {
        return $this->myClass->name . ' ' . $this->myClass->tag;
    }
}
```

However to process these fields with these methods you will need to use the `processTask` method:

```
$myClassInstance->processTaskWith('configure','search_text');
```

In the same way, these methods can also accept parameters:

```
namespace App\Keepers;

use \App\Models\MyClass;

class MyClassKeeper
{
    // ...
    public function configureSearchTextWith($whatever)
    {
        return $this->myClass->name . ' ' . $this->myClass->tag;
    }
}
```

The you would do:

```
$myClassInstance->processTaskWith('configure','search_text', 'Any string');
```

You can also pass an array of fields to process all of them at the same time:

```
$myClassInstance->processTask('configure', ['search_text', 'word_count']);
```

Saving data
-----------

[](#saving-data)

The attributes will not be saved to the database. In order to do that, call the `save` method as usually:

```
$myClassInstance->process('configure')->save();
```

Sponsors
--------

[](#sponsors)

Larakeep is supported by the following sponsors. Thank you for keeping it growing:

 [![Kenodo](art/logo-kenodo.png)](https://kenodo.com) [Kenodo](https://kenodo.com) [![AndorraDev](art/logo-andorradev.png)](https://andorradev.com) [AndorraDev](https://andorradev.com)

Author
------

[](#author)

Created by [Edu Lazaro](https://edulazaro.com)

License
-------

[](#license)

Larakeep is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance90

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~166 days

Recently: every ~120 days

Total

7

Last Release

50d ago

Major Versions

1.0.5 → v2.0.02025-03-03

PHP version history (2 changes)1.0.5PHP ^8.1

v2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a3c47449dfb2ec121aa410da024f47586b87cc2799a825f0418e6c5e5904955?d=identicon)[edulazaro](/maintainers/edulazaro)

---

Top Contributors

[![edulazaro](https://avatars.githubusercontent.com/u/7797530?v=4)](https://github.com/edulazaro "edulazaro (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/edulazaro-larakeep/health.svg)

```
[![Health](https://phpackages.com/badges/edulazaro-larakeep/health.svg)](https://phpackages.com/packages/edulazaro-larakeep)
```

###  Alternatives

[crumbls/layup

A visual page builder plugin for Filament 5 — Divi-style grid layouts with extensible widgets.

604.0k2](/packages/crumbls-layup)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3622.8k](/packages/duncanmcclean-statamic-cargo)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.8k](/packages/tomshaw-electricgrid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
