2016-03-28 11:26:43 -07:00
|
|
|
# Read Only Laravel 5 Models
|
|
|
|
The Read only trait Monkey Patches Laravel models to not save, delete or modify models.
|
|
|
|
Ideally, this would be used in addition to DB permissions to ensure Users and Developers cannot write to a Legacy system of some kind.
|
|
|
|
|
|
|
|
This is only a simple demonstration of the model.
|
|
|
|
## To use:
|
|
|
|
|
|
|
|
```php
|
|
|
|
<?php
|
|
|
|
require_once('src/ReadOnlyTrait.php'); //Or register under your config/App.php
|
2016-03-28 11:38:08 -07:00
|
|
|
// use MichaelAChrisco\ReadOnlyTrait; //optional
|
2016-03-28 11:26:43 -07:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2016-12-06 11:16:18 -08:00
|
|
|
class User extends Model {
|
2016-03-28 11:38:08 -07:00
|
|
|
use MichaelAChrisco\ReadOnly\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 $result is false.
|
|
|
|
?>
|
|
|
|
```
|
2016-12-06 11:16:18 -08:00
|
|
|
|
|
|
|
## Methods that will return false:
|
|
|
|
|
|
|
|
* 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
|
|
|
|
|
|
|
|
###
|