{"id":13990453,"url":"https://github.com/victorlap/laravel-approvable","last_synced_at":"2025-12-30T08:07:14.644Z","repository":{"id":16646111,"uuid":"80375034","full_name":"victorlap/laravel-approvable","owner":"victorlap","description":"Easily add an approval process to any laravel model.","archived":true,"fork":false,"pushed_at":"2021-04-29T19:12:15.000Z","size":50,"stargazers_count":85,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-09T13:17:21.174Z","etag":null,"topics":["approvable","approval","approval-process","eloquent","hacktoberfest","laravel"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/victorlap.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-29T21:49:35.000Z","updated_at":"2024-08-09T13:17:21.174Z","dependencies_parsed_at":"2022-08-07T08:15:30.496Z","dependency_job_id":null,"html_url":"https://github.com/victorlap/laravel-approvable","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorlap%2Flaravel-approvable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorlap%2Flaravel-approvable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorlap%2Flaravel-approvable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorlap%2Flaravel-approvable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/victorlap","download_url":"https://codeload.github.com/victorlap/laravel-approvable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227098794,"owners_count":17730638,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["approvable","approval","approval-process","eloquent","hacktoberfest","laravel"],"created_at":"2024-08-09T13:02:44.740Z","updated_at":"2025-12-13T05:49:57.865Z","avatar_url":"https://github.com/victorlap.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Laravel Approvable\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status][ico-travis]][link-travis]\n[![Coverage Status][ico-scrutinizer]][link-scrutinizer]\n[![Quality Score][ico-code-quality]][link-code-quality]\n[![StyleCI](https://styleci.io/repos/80375034/shield?branch=master)](https://styleci.io/repos/80375034)\n[![Total Downloads][ico-downloads]][link-downloads]\n\nEasily add an approval process to any laravel model.\n\n## Description\n\nLaravel Approvable is a package which helps when you have certain models in your application that should be editable by users, but the fields that they edit need to be approved first.\n\n## Installation\n\nVia Composer\n\n``` bash\n$ composer require victorlap/laravel-approvable\n```\n\nYou can publish the migration with:\n```bash\nphp artisan vendor:publish --provider=\"Victorlap\\Approvable\\ApprovableServiceProvider\" --tag=\"migrations\"\nphp artisan migrate\n```\n\n## Setup\nAssume you have a `Post` model. Each visitor on your site can edit any post, but before you want to publish the change to your website, you want to approve it first. By adding the `\\Victorlap\\Approvable\\Approvable` trait to your `Post` model, when a visitor makes a change, a change request gets stored in the database. These changes can then later be applied, or denied by administrators. The  `currentUserCanApprove` method can be used to determine who is authorized to make a change.\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Victorlap\\Approvable\\Approvable;\n\n// Minimal\nclass Post extends Model\n{\n    use Approvable;   \n}\n\n// Extended\nclass Post extends Model\n{\n    use Approvable;\n\n    protected $approveOf = array();\n\n    protected $dontApproveOf = array();\n    \n    protected function currentUserCanApprove()\n    {\n        return Auth::check();\n    }\n    \n    protected function getSystemUserId()\n    {\n        return Auth::id();\n    }\n}\n```\n\n## Usage\nMaking a change to a model by a user who can approve does not change.\n```php\n$post-\u003etitle = \"Very Good Post\";\n$post-\u003esave(); // This still works!\n```\n\nMaking a change by an unauthorized user works the same.\n```php\n$post-\u003etitle = \"Very Good Post\";\n$post-\u003esave(); // Post remains with the old title in the database, however a change request is now also present.\n```\n\nYou can retrieve a list of attributes that have pending changes by using\n```php\n$post-\u003egetPendingApprovalAttributes();\n```\n\nOr check if a certain attribute has pending changes\n```php\n$post-\u003eisPendingApproval('title');\n```\n\nScopes have been defined to quickly see approvals in different states. For example if you wnat to show administrators a list with changes that can be accepted you can use the `open` scope. Other scopes are `accepted`, `rejected` and `ofClass`.\n```php\nApproval::open()-\u003eget();\nApproval::accepted()-\u003eget();\nApproval::rejected()-\u003eget();\nApproval::ofClass(Post::class)-\u003eget();\n```\n\nYou can combine the scopes of course, or use them in combination with regular query builder methods\n```php\nApproval::open()-\u003eofClass(Post::class)-\u003eget();\n```\n\nAccepting and rejecting of approvals can be done using the `accept` and `reject` methods on the Approval.\n```php\n$approvals = Post::find(1)-\u003eapprovals()-\u003eopen()-\u003eget();\n$approvals-\u003eeach-\u003eaccept(); // or\n$approvals-\u003eeach-\u003ereject();\n```\n\nIf you dont want a model to pass approval, you can use the `withoutApproval()` method.\n```php\n// Now this post model is not checked for changes.\n$post-\u003ewithoutApproval()\n      -\u003efill([\n        'title' =\u003e 'A new title',\n      ])\n      -\u003esave();\n```\n\nTo re-enable the approval for this model instance, you can use the `withApproval()` method.\n\n## Limitations\nCurrently Approvable does not handle creation of models, PR's are welcome for this.\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email victorlap@outlook.com instead of using the issue tracker.\n\n## Credits\n\n- [Victor Lap][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/victorlap/laravel-approvable.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/victorlap/laravel-approvable/master.svg?style=flat-square\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/victorlap/laravel-approvable.svg?style=flat-square\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/victorlap/laravel-approvable.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/victorlap/laravel-approvable.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/victorlap/laravel-approvable\n[link-travis]: https://travis-ci.org/victorlap/laravel-approvable\n[link-scrutinizer]: https://scrutinizer-ci.com/g/victorlap/laravel-approvable/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/victorlap/laravel-approvable\n[link-downloads]: https://packagist.org/packages/victorlap/laravel-approvable\n[link-author]: https://github.com/victorlap\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorlap%2Flaravel-approvable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictorlap%2Flaravel-approvable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorlap%2Flaravel-approvable/lists"}