michaelachrisco/readonly

Readonly Models for Laravel 5+
2,288,426 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

Total Downloads build workflow Latest Version on Packagist

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

spatie/laravel-translatable

A trait to make an Eloquent model hold translations

30,089,119 2,462
spatie/laravel-sluggable

Generate slugs when saving Eloquent models

14,394,488 1,555
kodeine/laravel-acl

Light-weight role-based permissions for Laravel 5 built in Auth system.

364,261 774
hootlex/laravel-friendships

This package gives Eloquent models the ability to manage their friendships.

125,940 698