Laravel Read Only Model Traits
Find a file
Michael Chrisco 276836059b
Merge pull request #57 from michaelachrisco/56-add-context-to-kahlan
feat(spec): Testing users should have more context
2024-01-17 12:15:36 -08:00
.circleci fix(circleci): Library should work with php 8.3 2024-01-17 12:11:19 -08:00
spec feat(spec): Testing class with isActive 2024-01-17 12:08:41 -08:00
src Add deprecation highlighting on disallowed methods (#47) (#49) 2023-02-02 11:57:21 -08:00
.gitignore Add PHP-CS-Fixer to linting process and Travis. 2017-03-31 11:40:47 -07:00
composer.json fix(composer): Blanket update on testing library 2023-10-27 13:10:59 -07:00
LICENSE License (#13) 2017-03-23 09:34:11 -07:00
README.md feat(readme): Number of downloads 2023-12-18 09:24:15 -08:00

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.

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!