ReadOnlyTraitLaravel/README.md

67 lines
1.1 KiB
Markdown
Raw Normal View History

# 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
```
2016-03-28 11:26:43 -07:00
## To use:
2016-03-28 11:26:43 -07:00
```php
<?php
use Illuminate\Database\Eloquent\Model;
use MichaelAChrisco\ReadOnly\ReadOnlyTrait;
2016-12-06 11:16:18 -08:00
class User extends Model {
use ReadOnlyTrait;
2016-03-28 11:26:43 -07:00
}
$legacyUser = new User;
$legacyUser->set_user_name('bob');
2016-12-06 11:16:18 -08:00
2016-03-28 11:26:43 -07:00
$result = $legacyUser->save();
//User is not saved and ReadOnlyException is thrown.
2016-03-28 11:26:43 -07:00
?>
```
2016-12-06 11:16:18 -08:00
## Methods that will throw ReadOnlyExceptions:
2016-12-06 11:16:18 -08:00
* create
* forceCreate
* save
* update
* firstOrCreate
* firstOrNew
* delete
* destroy
* restore
* forceDelete
2016-12-09 06:37:13 -08:00
* performDeleteOnModel
* push
* finishSave
* performUpdate
* touch
2016-12-06 11:16:18 -08:00
## 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
###