Laravel Read Only Model Traits
Find a file
2017-03-23 09:34:11 -07:00
spec Hotfix on performUpdate. Silent fail from kahlan. 2016-12-09 07:19:04 -08:00
src Hotfix on performUpdate. Silent fail from kahlan. 2016-12-09 07:19:04 -08:00
.gitignore init 2016-03-28 11:15:08 -07:00
.travis.yml Fix Travis 2016-03-28 11:30:42 -07:00
composer.json Add namespace autoload to composer.json (#4) 2016-12-06 16:51:43 -08:00
LICENSE License (#13) 2017-03-23 09:34:11 -07:00
README.md Grammar and composer instructions (#11) 2017-02-08 12:51:15 -08:00

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;
class User extends Model {
  use \MichaelAChrisco\ReadOnly\ReadOnlyTrait;
}

$legacyUser = new User;
$legacyUser->set_user_name('bob');

$result = $legacyUser->save();
//User is not saved and $result is false.
 ?>

Methods that will return false:

  • create
  • forceCreate
  • save
  • update
  • firstOrCreate
  • firstOrNew
  • delete
  • destroy
  • restore
  • forceDelete
  • performDeleteOnModel
  • push
  • finishSave
  • performUpdate
  • touch

TODO:

  • saveOrFail
  • performInsert(??)
  • insertAndSetId(??)
  • Add in a PR for any other methods you can find!

registerModelEvents( look into best way to implement)

  • saving
  • saved
  • updating
  • updated
  • creating
  • created
  • deleting
  • deleted