https://github.com/dillingham/ownable
automatic auth user model attachment & policy
https://github.com/dillingham/ownable
laravel
Last synced: 2 months ago
JSON representation
automatic auth user model attachment & policy
- Host: GitHub
- URL: https://github.com/dillingham/ownable
- Owner: dillingham
- License: mit
- Created: 2019-08-24T02:20:01.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-07T20:07:24.000Z (almost 7 years ago)
- Last Synced: 2025-03-31T20:13:44.806Z (over 1 year ago)
- Topics: laravel
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# Ownable
[](https://packagist.org/packages/dillingham/ownable)
[](https://packagist.org/packages/dillingham/ownable) [](https://twitter.com/dillinghammm)
### Install
```
composer require dillingham/ownable
```
- add `Ownable` trait to model(s)
- add `owned()` to limit models to auth user
### What it does:
- automatically applies auth user id when creating models
- automatically prevents update / delete unless owner
- provides an `owned()` scope to apply to queries
### Policy
Adding a policy to the model will remove update / delete gates.
Extend OwnerPolicy if you want or manually add those in your policy.
```php
class UserPolicy extends OwnerPolicy
{
public view($user, $model)
{
//
}
}
```