LaravelPackages.net
Acme Inc.
Toggle sidebar
michaelachrisco/readonly

Readonly Models for Laravel 5+

2.183.037
162
v1.1.0
About michaelachrisco/readonly

michaelachrisco/readonly is a Laravel package for readonly models for laravel 5+. It currently has 162 GitHub stars and 2.183.037 downloads on Packagist (latest version v1.1.0). Install it with composer require michaelachrisco/readonly. Discover more Laravel packages by michaelachrisco or browse all Laravel packages to compare alternatives.

Last updated

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!

Star History Chart