michaelachrisco/readonly
Readonly Models for Laravel 5+
2,347,926
162
| Install | |
|---|---|
composer require michaelachrisco/readonly |
|
| Latest Version: | v1.1.0 |
| PHP: | >=7.0.0 |
| License: | MIT |
| Last Updated: | Apr 2, 2026 |
| Links: | GitHub · Packagist |
Maintainer: michaelachrisco
Laravel 5+ Read Only Models
The read only trait removes the ability to save, delete or modify Laravel models. Ideally, this would be used in addition to DB permissions to ensure users and developers cannot write to a Legacy system.
Install
composer require michaelachrisco/readonly
To use:
<?php
use Illuminate\Database\Eloquent\Model;
use MichaelAChrisco\ReadOnly\ReadOnlyTrait;
class User extends Model {
use ReadOnlyTrait;
}
$legacyUser = new User;
$legacyUser->set_user_name('bob');
$result = $legacyUser->save();
//User is not saved.
//ReadOnlyException is thrown.
?>
Methods that will throw ReadOnlyExceptions:
- create
- forceCreate
- save
- update
- firstOrCreate
- firstOrNew
- delete
- destroy
- restore
- forceDelete
- performDeleteOnModel
- push
- finishSave
- performUpdate
- touch
- insert
- truncate
- Add in a PR for any other methods you can find!
Related Packages
martinbean/laravel-sluggable-trait
A trait you can apply to Eloquent models to have slugs automatically generated o...
49,126
24
isswp101/elasticsearch-eloquent
Elasticsearch functionality like Laravel Eloquent models.
25,593
112
Version History
| Version | Released | PHP | License |
|---|---|---|---|
| v1.1.0 | >=7.0.0 | MIT | |
| v1.0.0 | >=7.0.0 | MIT | |
| v0.60.1 | >=7.0.0 | MIT | |
| v0.60.0 | >=7.0.0 | MIT | |
| v0.50.0 | >=7.0.0 | MIT | |
| v0.40.1 | >=7.0.0 | MIT | |
| v0.40 | >=7.0.0 | MIT | |
| v0.34 | >=7.0.0 | MIT | |
| 0.33 | >=7.0.0 | MIT | |
| v0.32 | >=7.0.0 | MIT | |
| v0.31 | >=7.0.0 | ||
| v0.30 | >=7.0.0 | ||
| v0.20.1 | >=5.5.9 | ||
| v0.20 | >=5.5.9 | ||
| v0.10 | >=5.5.9 |