PHPackages                             robertbaelde/laravel\_read\_only\_fields - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. robertbaelde/laravel\_read\_only\_fields

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

robertbaelde/laravel\_read\_only\_fields
========================================

Protect read only fields from accidentally being updated

1.0.0(5y ago)012.0k↓40.6%MITPHPPHP ^7.4|^8.0

Since Apr 14Pushed 5y agoCompare

[ Source](https://github.com/Robertbaelde/laravel-read-only-fields)[ Packagist](https://packagist.org/packages/robertbaelde/laravel_read_only_fields)[ Docs](https://github.com/temperworks/laravel_read_only_fields)[ RSS](/packages/robertbaelde-laravel-read-only-fields/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (4)Used By (0)

Laravel read only fields
========================

[](#laravel-read-only-fields)

[![GitHub Tests Action Status](https://camo.githubusercontent.com/73606e84a1a22a5f8fd3aaafd471a803cf52404e0a1bd2e5ea6037c4841126d2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f74656d706572776f726b732f6c61726176656c2d726561642d6f6e6c792d6669656c64732f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/TemperWorks/laravel-read-only-fields/actions?query=workflow%3Arun-tests+branch%3Amain)

Laravel read only fields lets you guard fields against unexpected updates.

An example use case for this might be when a projector in an event sourced system updates a read model. You want to make sure that the read model only gets updated by the projector.

Guarding fields on a model
--------------------------

[](#guarding-fields-on-a-model)

To guard fields use the `HasReadOnlyFields` trait in your model, and specify the read only fields by creating an array on your model named `$readOnlyFields`

```
use Illuminate\Database\Eloquent\Model;
use Temperworks\ReadOnlyFields\HasReadOnlyFields;

class YourModel extends Model
{
    use HasReadOnlyFields;

    protected array $readOnlyFields = [
        'read_only_field'
    ];
}
```

Updating read only fields
-------------------------

[](#updating-read-only-fields)

When you want to update a read only field, you can mark that you intend to update the field by using `writable(['read_only_field'])`. After the model is saved, the writable state is reset.

```
$model = YourModel::find(1);
$model->writable(['read_only_field'])->update(['read_only_field' => 'foo']);

// this will throw an exception since we already updated the model.
$model->update(['read_only_field' => 'foobar']);
```

Credits
-------

[](#credits)

- [Robert Baelde](https://github.com/robertbaelde)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

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

Unknown

Total

1

Last Release

1907d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eff6bb65242a841ba6e68447ec06501ae0d269c060779417869ea2af012917c5?d=identicon)[robertbaelde](/maintainers/robertbaelde)

---

Top Contributors

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

---

Tags

laravelRead onlyevent sourcingTemperWorkslaravel\_read\_only\_fieldswrite protect

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/robertbaelde-laravel-read-only-fields/health.svg)

```
[![Health](https://phpackages.com/badges/robertbaelde-laravel-read-only-fields/health.svg)](https://phpackages.com/packages/robertbaelde-laravel-read-only-fields)
```

###  Alternatives

[askedio/laravel5-profanity-filter

A Vendor Package Example

53364.5k](/packages/askedio-laravel5-profanity-filter)[dialect/laravel-gdpr-compliance

GDPR compliant data portability and anonymization

57120.4k](/packages/dialect-laravel-gdpr-compliance)[laravel-validation-rules/us-state

Validate US States and Canada Provinces

16181.0k](/packages/laravel-validation-rules-us-state)[pacerit/laravel-polish-validation-rules

Simple Polish Validation rules for Laravel and Lumen framework

1453.9k](/packages/pacerit-laravel-polish-validation-rules)[laravel-validation-rules/ip

Validate if an ip address is public or private.

1629.7k](/packages/laravel-validation-rules-ip)[janvince/smallcontactform

Simple but flexible multi language contact form builder with custom fields, validation and passive antispam

307.9k](/packages/janvince-smallcontactform)

PHPackages © 2026

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