Readonly Models for Laravel 5+

v0.60.1 2023-10-27 20:15 UTC

This package is auto-updated.

Last update: 2024-02-17 20:35:41 UTC


Latest Version on Packagist CircleCI Total Downloads

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.


composer require michaelachrisco/readonly

To use:

use Illuminate\Database\Eloquent\Model;
use MichaelAChrisco\ReadOnly\ReadOnlyTrait;
class User extends Model {
  use ReadOnlyTrait;

$legacyUser = new User;

$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!